-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsave_notes_to_nb.py
63 lines (49 loc) · 1.26 KB
/
save_notes_to_nb.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import requests, json, subprocess, re
from dotenv import load_dotenv
load_dotenv()
IP = os.getenv("IP")
URL = IP+"/notes"
PASSWORD = "@3rooycA -1"
NOTEBOOK = "acustic"
def get_notes():
response = requests.get(URL, params={"the_p": PASSWORD, "notebook": NOTEBOOK})
return response.json()
try:
notes = get_notes()["notes"]
except:
exit()
if not notes:
exit()
for note in notes:
content = note["content"]
idd = note["id"]
is_todo = note["is_todo"]
is_bookmark = note["is_bookmark"]
timestamp = note["timestamp"]
tags = note["tags"]
if tags:
tags = ",".join(tags)
#remove # from tags
tags = tags.replace("#", "")
print(tags)
# check if content is a url
match = re.search(r"(?P<url>https?://[^\s]+)", content)
if is_bookmark and match and not is_todo:
if tags:
subprocess.run(["nb", match[0], "--tags", tags])
else:
subprocess.run(["nb", match[0]])
continue
if is_todo:
if tags:
subprocess.run(["nb", "todo", "a", content, "--tags", tags])
else:
subprocess.run(["nb", "todo", "a", content])
else:
if tags:
subprocess.run(["nb", "a", content, "--tags", tags])
else:
subprocess.run(["nb", "a", content])
para = {"the_p": PASSWORD, "id": str(idd), "notebook": NOTEBOOK}
response = requests.delete(URL, params=para)
print("="*50)