forked from axawzh/TextCleaner
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpostBook.py
More file actions
50 lines (36 loc) · 1.3 KB
/
postBook.py
File metadata and controls
50 lines (36 loc) · 1.3 KB
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
import logging
import pdf_client
from pdf_client import config
from pdf_client.api import book
from pdf_client.multithread.worker import MultiThreadWorker
from pdf_client.multithread.processor import TextProcessor
from main import CleanStart
# load global config, specify the location of the config.json here
config.load_from_file('./config.json')
class MyProcessor(TextProcessor):
def process(self, text, section_id):
cleaner = CleanStart()
text = cleaner.run(text)
return text
def book_list():
"""get a list of book_id's"""
book_list = list()
book_list_api = book.List().execute()
for book_dict in book_list_api:
book_list.append(book_dict['id'])
return book_list
def postbook(book_id):
# enable INFO level logging
logging.basicConfig()
logging.getLogger(pdf_client.multithread.worker.__name__).setLevel(logging.INFO)
# change the source and target argument here to specify the source target version.
worker = MultiThreadWorker(processor=MyProcessor(), book=book_id, source=1, target=5)
worker.start()
# completed = worker.start()
# for future in completed:
# section_id, text = future.result()
# # handle the results
# if __name__ == '__main__':
# main()
for book_id in book_list():
postbook(book_id)