-
Notifications
You must be signed in to change notification settings - Fork 3
/
add_pdf_previews.py
60 lines (54 loc) · 1.45 KB
/
add_pdf_previews.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
import click
from joplin import joplinapi
from joplin import joplintools
import time
import sys
@click.command()
@click.option(
"-n",
"--notebook",
"notebook",
required=False,
help="""Specify the notebook for the search.""",
)
@click.option(
"-t",
"--token",
"token",
required=False,
help="""Specify the Joplin API token.""",
)
@click.option(
"-u",
"--url",
"url",
required=False,
default="http://localhost:41184",
show_default=True,
help="""Specify the Joplin web clipper URL.""",
)
def Main(notebook, token, url):
if token is not None:
joplinapi.SetEndpoint(url, token)
elif joplinapi.LoadEndpoint() == False:
joplinapi.SetEndpoint(url, token)
while joplinapi.Ping() == False:
print("Wait for Joplin")
time.sleep(10)
query = "resource:application/pdf"
if notebook is not None:
query += ' notebook:"' + notebook + '"'
page = 1
while True:
note_ids = joplinapi.Search(query=query,type="note", fields="id", limit=2, page=page)
count = 1
for note in note_ids['items']:
if count % 10 == 0:
print("Process 1 of " + str(len(note_ids['items'])) + " notes from batch " + str(page))
joplintools.AddPDFPreviewToNote(note['id'])
count += 1
page += page
if note_ids['has_more'] == False:
break;
if __name__ == "__main__":
Main()