I nga wa katoa ka hiahia ahau ki te pehea e pai ai te tohatoha pukapuka ki taku whare pukapuka hiko. I te mutunga, ka tae mai ahau ki tenei whiringa me te tatau aunoa i te maha o nga whaarangi me etahi atu mea pai. Ka patai ahau ki nga tangata whai paanga katoa i raro i te ngeru.
Wāhanga 1. Dropbox
Ko aku pukapuka katoa kei runga dropbox. E 4 nga wahanga i wehewehea e au nga mea katoa: Pukapuka, Tohutoro, Pakiwaitara, Korero-kore. Engari kaore au e tapiri pukapuka tohutoro ki te tepu.
Ko te nuinga o nga pukapuka he .epub, ko te toenga he .pdf. Arā, ko te otinga whakamutunga me hipoki nga whiringa e rua.
He penei aku huarahi ki nga pukapuka:
/Книги/Нехудожественное/Новое/Дизайн/Юрий Гордон/Книга про буквы от А до Я.epub
Mēnā he pakiwaitara te pukapuka, kātahi ka tangohia te kāwai (arā, “Hoahoa” i te kēhi o runga ake nei).
I whakatau ahau kia kaua e whakararuraru i te Dropbox API, na te mea kei a au ta raatau tono e tukutahi ana i te kōpaki. Arā, ko te mahere tenei: ka tango pukapuka mai i te kōpaki, ka whakahaere i ia pukapuka ma te porotiti kupu, ka taapiri atu ki te Notion.
Wāhanga 2. Tāpirihia he raina
Ko te teepu ake me penei te ahua. WHAKATOKANGA: he pai ake te hanga i nga ingoa pou ki te reo Latina.
Ka whakamahia e matou te API Notion kore mana, na te mea kaore ano kia tukuna mai te mana mana.
Haere ki te Notion, pehia Ctrl + Shift + J, haere ki te Taupānga -> Pihikete, kape token_v2 ka karangahia TOKEN. Katahi ka haere ki te wharangi e hiahiatia ana me te tohu whare pukapuka ka kape i te hono. Ka kiia e matou ko NOTION.
Na ka tuhia e matou te waehere hei hono atu ki a Notion.
database = client.get_collection_view(NOTION)
current_rows = database.default_query().execute()
Whai muri, me tuhi he mahi hei taapiri rarangi ki te ripanga.
def add_row(path, file, words_count, pages_count, hours):
row = database.collection.add_row()
row.title = file
tags = path.split("/")
if len(tags) >= 1:
row.what = tags[0]
if len(tags) >= 2:
row.state = tags[1]
if len(tags) >= 3:
if tags[0] == "Художественное":
row.author = tags[2]
elif tags[0] == "Нехудожественное":
row.tags = tags[2]
elif tags[0] == "Учебники":
row.tags = tags[2]
if len(tags) >= 4:
row.author = tags[3]
row.hours = hours
row.pages = pages_count
row.words = words_count
He aha kei konei. Ka tangohia, ka taapirihia he rarangi hou ki te tepu i te rarangi tuatahi. I muri mai, ka wehewehea to maatau huarahi ki te "/" ka whiwhi tohu. Nga tohu - mo te "Toi", "Hoahoa", ko wai te kaituhi, me etahi atu. Na ka whakaturia e matou nga waahi katoa o te pereti.
Wāhanga 3. Te tatau i ngā kupu, ngā hāora me ērā atu mea pai
He mahi uaua ake tenei. E maumahara ana matou, e rua nga whakatakotoranga: epub me te pdf. Mena kei te marama nga mea katoa me te epub - kei reira pea nga kupu, karekau i te tino marama nga mea katoa mo te pdf: tera pea he whakaahua taapiri.
Na ko ta maatau mahi mo te tatau kupu i roto i te PDF ka penei te ahua: ka tango i te maha o nga wharangi ka whakareatia ki tetahi tau (te tau toharite o nga kupu mo ia wharangi).
Anei ia:
def get_words_count(pages_number):
return pages_number * WORDS_PER_PAGE
Ko tenei WORDS_PER_PAGE mo te wharangi A4 he 300 pea.
Inaianei me tuhi he mahi hei tatau wharangi. Ka whakamahia e matou
def get_pdf_pages_number(path, filename):
pdf = PdfFileReader(open(os.path.join(path, filename), 'rb'))
return pdf.getNumPages()
I muri mai, ka tuhia e matou he mea mo te tatau wharangi ki Epub. Ka whakamahia e matou
def get_epub_pages_number(path, filename):
book = open_book(os.path.join(path, filename))
lines = convert_epub_to_lines(book)
words_count = 0
for line in lines:
words_count += len(line.split(" "))
return round(words_count / WORDS_PER_PAGE)
Inaianei me tatau te taima. Ka tangohia e matou te tatau kupu tino pai ka wehewehea e to tere panui.
def get_reading_time(words_count):
return round(((words_count / WORDS_PER_MINUTE) / 60) * 10) / 10
Wāhanga 4. Te hono i ngā wāhanga katoa
Me haere tatou ma nga huarahi katoa e taea ana i roto i a tatou kōpaki pukapuka. Tirohia mena he pukapuka kei roto i te Notion: mena kei reira, kaore e tika kia hanga raina.
Na me whakatau te momo konae, a, i runga ano i tenei, tatauhia te maha o nga kupu. Tāpirihia he pukapuka ki te mutunga.
Koinei te waehere ka whiwhi tatou:
for root, subdirs, files in os.walk(BOOKS_DIR):
if len(files) > 0 and check_for_excusion(root):
for file in files:
array = file.split(".")
filetype = file.split(".")[len(array) - 1]
filename = file.replace("." + filetype, "")
local_root = root.replace(BOOKS_DIR, "")
print("Dir: {}, file: {}".format(local_root, file))
if not check_for_existence(filename):
print("Dir: {}, file: {}".format(local_root, file))
if filetype == "pdf":
count = get_pdf_pages_number(root, file)
else:
count = get_epub_pages_number(root, file)
words_count = get_words_count(count)
hours = get_reading_time(words_count)
print("Pages: {}, Words: {}, Hours: {}".format(count, words_count, hours))
add_row(local_root, filename, words_count, count, hours)
A ko te mahi ki te tirotiro mena kua taapirihia he pukapuka penei te ahua:
def check_for_existence(filename):
for row in current_rows:
if row.title in filename:
return True
elif filename in row.title:
return True
return False
mutunga
Nga mihi ki te hunga katoa i panui i tenei tuhinga. Ko taku tumanako ka awhina koe ki te panui ake :)
Source: will.com