-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerator.py
638 lines (509 loc) · 22.1 KB
/
generator.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
#!/usr/bin/python
import sqlite3
from shutil import copyfile
import pandas as pd
import os
import json
from json2xml import json2xml
from json2xml.utils import readfromjson
import asyncio
from PIL import Image
from pyppeteer import launch
from datetime import datetime
import glob
import shutil
from docx import Document
from docx.enum.text import WD_PARAGRAPH_ALIGNMENT
from docx.enum.table import WD_CELL_VERTICAL_ALIGNMENT, WD_TABLE_DIRECTION, WD_TABLE_ALIGNMENT
import pyexcel as pe
import csv
from config import *
def init():
if not os.path.exists('TEMP'):
os.makedirs('TEMP')
if not os.path.exists(RELEASE_DIR):
os.makedirs(RELEASE_DIR)
if not os.path.exists(RELEASE_DIR + '/CSV'):
os.makedirs(RELEASE_DIR + '/CSV')
if not os.path.exists(RELEASE_DIR + '/docs'):
os.makedirs(RELEASE_DIR + '/docs')
if not os.path.exists(RELEASE_DIR + '/Excel'):
os.makedirs(RELEASE_DIR + '/Excel')
if not os.path.exists(RELEASE_DIR + '/Flash Card'):
os.makedirs(RELEASE_DIR + '/Flash Card')
if not os.path.exists(RELEASE_DIR + '/JSON'):
os.makedirs(RELEASE_DIR + '/JSON')
if not os.path.exists(RELEASE_DIR + '/PDF'):
os.makedirs(RELEASE_DIR + '/PDF')
if not os.path.exists(RELEASE_DIR + '/SQLite'):
os.makedirs(RELEASE_DIR + '/SQLite')
if not os.path.exists(RELEASE_DIR + '/Word'):
os.makedirs(RELEASE_DIR + '/Word')
if not os.path.exists(RELEASE_DIR + '/XML'):
os.makedirs(RELEASE_DIR + '/XML')
copyfile("./templates/favicon.png", RELEASE_DIR + "/docs/favicon.png")
copyfile("./templates/index.html", RELEASE_DIR + "/docs/index.html")
copyfile("./templates/CNAME", RELEASE_DIR + "/docs/CNAME")
copyfile("./templates/LICENSE", RELEASE_DIR + "/LICENSE")
def normalize(path: str = RELEASE_DIR + "/SQLite/Top 1000 Words in Gilaki.sqlite"):
try:
conn = sqlite3.connect(DB_DIR)
cursor = conn.cursor()
print("Connected to SQLite successfully .")
print("Normalization started...")
sqlite_update_query = "UPDATE tbl_words SET glk_word = trim(glk_word), glk_example = trim(glk_example), " \
"fa_word = trim(fa_word), fa_example = trim(fa_example), en_word = trim(en_word), " \
"en_example = trim(en_example) "
cursor.execute(sqlite_update_query)
conn.commit()
print("Records striped successfully.", cursor.rowcount)
cursor.close()
print("Releasing SQLite...")
copyfile(DB_DIR, RELEASE_DIR + "/SQLite/Top 1000 Words in Gilaki.sqlite")
print("SQLite Released Successfully.")
except sqlite3.Error as error:
print("Failed to stripe rows.", error)
finally:
if (conn):
conn.close()
print("The SQLite connection is closed.")
print("Sorting database started...")
copyfile("./templates/database.db", path)
try:
conn = sqlite3.connect(DB_DIR)
cursor = conn.cursor()
sqlite_select_query = '''SELECT * FROM tbl_words ORDER BY case
when glk_word like 'ٚ%' then 0
when glk_word like 'آ%' then 1
when glk_word like 'ا%' then 2
when glk_word like 'أ%' then 3
when glk_word like 'ب%' then 4
when glk_word like 'پ%' then 5
when glk_word like 'ت%' then 6
when glk_word like 'ث%' then 7
when glk_word like 'ج%' then 8
when glk_word like 'چ%' then 9
when glk_word like 'ح%' then 10
when glk_word like 'خ%' then 11
when glk_word like 'د%' then 12
when glk_word like 'ذ%' then 13
when glk_word like 'ر%' then 14
when glk_word like 'ز%' then 15
when glk_word like 'ژ%' then 16
when glk_word like 'س%' then 17
when glk_word like 'ش%' then 18
when glk_word like 'ص%' then 19
when glk_word like 'ض%' then 20
when glk_word like 'ط%' then 21
when glk_word like 'ظ%' then 22
when glk_word like 'ع%' then 23
when glk_word like 'غ%' then 24
when glk_word like 'ف%' then 25
when glk_word like 'ق%' then 26
when glk_word like 'ک%' then 27
when glk_word like 'گ%' then 28
when glk_word like 'ل%' then 29
when glk_word like 'م%' then 30
when glk_word like 'ن%' then 31
when glk_word like 'و%' then 32
when glk_word like 'ؤ%' then 33
when glk_word like 'ۊ%' then 34
when glk_word like 'ه%' then 35
when glk_word like 'ی%' then 36
when glk_word like 'ي%' then 37
when glk_word like 'ئ%' then 38
else 39
end asc, glk_word asc;'''
cursor.execute(sqlite_select_query)
records = cursor.fetchall()
i = 0
conn2 = sqlite3.connect(path)
for row in records:
i += 1
cursor2 = conn2.cursor()
r1 = row[1] # glk_word
r2 = row[2] # glk_example
r3 = row[3] # fa_word
r4 = row[4] # fa_example
r5 = row[5] # en_word
r6 = row[6] # en_example
r1 = r1.replace("'", "ٰ")
r1 = r1.replace("ٰ", " ٰ")
r1 = r1.replace("ˇ", " ٚ")
r1 = r1.replace("...", "…")
r2 = r2.replace("'", "ٰ")
r2 = r2.replace("ٰ", " ٰ")
r2 = r2.replace("ˇ", " ٚ")
r2 = r2.replace("...", "…")
r3 = r3.replace("ي", "ی")
r3 = r3.replace("...", "…")
r4 = r4.replace("ي", "ی")
r4 = r4.replace("...", "…")
r5 = r5.replace("...", "…")
r6 = r6.replace("...", "…")
sqlite_insert_query = f"""INSERT INTO tbl_words
(id, glk_word, glk_example, fa_word, fa_example, en_word, en_example)
VALUES
({i}, "{r1}", "{r2}", "{r3}", "{r4}", "{r5}", "{r6}")"""
cursor2.execute(sqlite_insert_query)
conn2.commit()
cursor.close()
except sqlite3.Error as error:
print("Failed to read data from sqlite table", error)
finally:
if (conn):
conn.close()
print("Database sorted Successfully.")
def make_csv():
print("Making CSV started...")
conn = sqlite3.connect(RELEASE_DIR + "/SQLite/Top 1000 Words in Gilaki.sqlite", isolation_level=None,
detect_types=sqlite3.PARSE_COLNAMES)
tmp_output_dir = RELEASE_DIR + "/CSV/Top 1000 Words in Gilaki (Full).csv"
db_df = pd.read_sql_query("SELECT * FROM tbl_words", conn)
db_df.to_csv(tmp_output_dir, index=False, quoting=csv.QUOTE_NONNUMERIC)
tmp_output_dir = RELEASE_DIR + "/CSV/Top 1000 Words in Gilaki (Farsi Only).csv"
db_df = pd.read_sql_query("SELECT id, glk_word, glk_example, fa_word, fa_example FROM tbl_words", conn)
db_df.to_csv(tmp_output_dir, index=False, quoting=csv.QUOTE_NONNUMERIC)
tmp_output_dir = RELEASE_DIR + "/CSV/Top 1000 Words in Gilaki (English Only).csv"
db_df = pd.read_sql_query("SELECT id, glk_word, glk_example, en_word, en_example FROM tbl_words", conn)
db_df.to_csv(tmp_output_dir, index=False, quoting=csv.QUOTE_NONNUMERIC)
print("CSV made Successfully.")
def make_json():
print("Making JSON started...")
conn = sqlite3.connect(RELEASE_DIR + "/SQLite/Top 1000 Words in Gilaki.sqlite")
conn.row_factory = sqlite3.Row
db = conn.cursor()
rows = db.execute("SELECT * from tbl_words").fetchall()
conn.commit()
conn.close()
js = json.dumps([dict(ix) for ix in rows], ensure_ascii=False).encode('utf8')
tmp_min_output_dir = RELEASE_DIR + "/JSON/Top 1000 Words in Gilaki.min.json"
f = open(tmp_min_output_dir, "w")
f.write(js.decode())
f.close()
tmp_output_dir = RELEASE_DIR + "/JSON/Top 1000 Words in Gilaki.json"
js = json.dumps([dict(ix) for ix in rows], indent=4, ensure_ascii=False).encode('utf8')
f = open(tmp_output_dir, "w")
f.write(js.decode())
f.close()
conn = sqlite3.connect(RELEASE_DIR + "/SQLite/Top 1000 Words in Gilaki.sqlite")
conn.row_factory = sqlite3.Row
db = conn.cursor()
rows = db.execute("SELECT id, glk_word, glk_example, fa_word, fa_example from tbl_words").fetchall()
conn.commit()
conn.close()
js = json.dumps([dict(ix) for ix in rows], ensure_ascii=False).encode('utf8')
tmp_min_output_dir = RELEASE_DIR + "/JSON/Top 1000 Words in Gilaki (Farsi Only).min.json"
f = open(tmp_min_output_dir, "w")
f.write(js.decode())
f.close()
tmp_output_dir = RELEASE_DIR + "/JSON/Top 1000 Words in Gilaki (Farsi Only).json"
js = json.dumps([dict(ix) for ix in rows], indent=4, ensure_ascii=False).encode('utf8')
f = open(tmp_output_dir, "w")
f.write(js.decode())
f.close()
conn = sqlite3.connect(RELEASE_DIR + "/SQLite/Top 1000 Words in Gilaki.sqlite")
conn.row_factory = sqlite3.Row
db = conn.cursor()
rows = db.execute("SELECT id, glk_word, glk_example, en_word, en_example from tbl_words").fetchall()
conn.commit()
conn.close()
js = json.dumps([dict(ix) for ix in rows], ensure_ascii=False).encode('utf8')
tmp_min_output_dir = RELEASE_DIR + "/JSON/Top 1000 Words in Gilaki (English Only).min.json"
f = open(tmp_min_output_dir, "w")
f.write(js.decode())
f.close()
tmp_output_dir = RELEASE_DIR + "/JSON/Top 1000 Words in Gilaki (English Only).json"
js = json.dumps([dict(ix) for ix in rows], indent=4, ensure_ascii=False).encode('utf8')
f = open(tmp_output_dir, "w")
f.write(js.decode())
f.close()
print("JSON made Successfully.")
def update_docs():
print("Updating docs...")
copyfile(RELEASE_DIR + "/JSON/Top 1000 Words in Gilaki.min.json", RELEASE_DIR + "/docs/Top 1000 Words in "
"Gilaki.min.json")
print("docs updated Successfully.")
def make_xml():
print("Making XML started...")
tmp_output_dir = RELEASE_DIR + "/XML/Top 1000 Words in Gilaki.xml"
data = readfromjson(RELEASE_DIR + "/JSON/Top 1000 Words in Gilaki.min.json")
data = json2xml.Json2xml(data, wrapper="wordlist", pretty=True, attr_type=False).to_xml()
data = data.replace("<item>", "<word>")
data = data.replace("</item>", "</word>")
data = data.replace('<?xml version="1.0" ?>', '<?xml version="1.0" encoding="UTF-8"?>')
f = open(tmp_output_dir, "w")
f.write(data)
f.close()
tmp_output_dir = RELEASE_DIR + "/XML/Top 1000 Words in Gilaki (Farsi Only).xml"
data = readfromjson(RELEASE_DIR + "/JSON/Top 1000 Words in Gilaki (Farsi Only).min.json")
data = json2xml.Json2xml(data, wrapper="wordlist", pretty=True, attr_type=False).to_xml()
data = data.replace("<item>", "<word>")
data = data.replace("</item>", "</word>")
data = data.replace('<?xml version="1.0" ?>', '<?xml version="1.0" encoding="UTF-8"?>')
f = open(tmp_output_dir, "w")
f.write(data)
f.close()
tmp_output_dir = RELEASE_DIR + "/XML/Top 1000 Words in Gilaki (English Only).xml"
data = readfromjson(RELEASE_DIR + "/JSON/Top 1000 Words in Gilaki (English Only).min.json")
data = json2xml.Json2xml(data, wrapper="wordlist", pretty=True, attr_type=False).to_xml()
data = data.replace("<item>", "<word>")
data = data.replace("</item>", "</word>")
data = data.replace('<?xml version="1.0" ?>', '<?xml version="1.0" encoding="UTF-8"?>')
f = open(tmp_output_dir, "w")
f.write(data)
f.close()
print("XML made Successfully.")
def readtemplate(path: str) -> str:
f = open(f"{path}", "r")
return f.read()
def make_flash_html(path: str = RELEASE_DIR + "/SQLite/Top 1000 Words in Gilaki.sqlite"):
print("Making HTML flashcards started...")
word = readtemplate("./templates/word.html")
meaning = readtemplate("./templates/meaning.html")
full = readtemplate("./templates/full_fa.html")
full_en = readtemplate("./templates/full_en.html")
try:
conn = sqlite3.connect(path)
cursor = conn.cursor()
sqlite_select_query = "SELECT * from tbl_words"
cursor.execute(sqlite_select_query)
records = cursor.fetchall()
for row in records:
flash = word
flash = flash.replace("{glk_word}", row[1])
createflash(f"{row[0]}-word.html", flash)
for row in records:
flash = meaning
flash = flash.replace("{glk_word}", row[1])
flash = flash.replace("{glk_example}", row[2])
createflash(f"{row[0]}-meaning.html", flash)
for row in records:
txt = ""
flash = full
flash = flash.replace("{glk_word}", row[1])
txt += row[1] + "\n"
flash = flash.replace("{fa_word}", row[3])
txt += row[3] + "\n"
flash = flash.replace("{glk_example}", row[2])
txt += row[2] + "\n"
flash = flash.replace("{fa_example}", row[4])
txt += row[4] + "\n"
createflash(f"{row[0]}-full-fa.html", flash)
txt += row[5] + "\n"
txt += row[6] + "\n"
createinfo(f"{row[0]}.txt", txt)
for row in records:
txt = ""
flash = full_en
flash = flash.replace("{glk_word}", row[1])
txt += row[1] + "\n"
flash = flash.replace("{en_word}", row[5])
txt += row[3] + "\n"
flash = flash.replace("{glk_example}", row[2])
txt += row[2] + "\n"
flash = flash.replace("{en_example}", row[6])
txt += row[4] + "\n"
createflash(f"{row[0]}-full-en.html", flash)
cursor.close()
except sqlite3.Error as error:
print("Failed to read data from sqlite table", error)
finally:
if (conn):
conn.close()
print("HTML flashcards made Successfully.")
def crop_center(pil_img, crop_width, crop_height):
img_width, img_height = pil_img.size
return pil_img.crop(((img_width - crop_width) // 2,
(img_height - crop_height) // 2,
(img_width + crop_width) // 2,
(img_height + crop_height) // 2))
def makejpg(typ):
for i in range(START_RANGE, END_RANGE, 1):
async def main():
browser = await launch(headless=True, options={'args': ['--no-sandbox']})
page = await browser.newPage()
await page.setViewport({'width': 600, 'height': 600})
p = os.path.abspath(f"TEMP/{i}-{typ}.html")
await page.goto(f"file://{p}")
await page.screenshot({'path': f"TEMP/{i}-{typ}.jpg"})
await browser.close()
asyncio.get_event_loop().run_until_complete(main())
thumb_width = 600
im = Image.open(f"TEMP/{i}-{typ}.jpg")
im_thumb = crop_center(im, thumb_width, thumb_width)
im_thumb.save(f"TEMP/{i}-{typ}.jpg", quality=100)
def createflash(name, html):
f = open(f"TEMP/{name}", "w")
f.write(html)
f.close()
def createinfo(name, text):
f = open(f"TEMP/{name}", "w")
f.write(text)
f.close()
def make_flash_jpg():
print("Making JPG flashcards started...")
makejpg("word")
makejpg("meaning")
makejpg("full-fa")
makejpg("full-en")
print("JPG flashcards made Successfully.")
print("Releasing JPG flashcards...")
files = glob.iglob(os.path.join("./TEMP/", "*.jpg"))
for file in files:
if os.path.isfile(file):
shutil.copy2(file, RELEASE_DIR + "/Flash Card/")
print("JPG flashcards Released Successfully.")
def make_gif(lang_code: str):
print(f"Making {lang_code} GIF flashcards started...")
def makegif(num):
os.system(
f'convert -delay 200 -loop 0 ./TEMP/{num}-word.jpg ./TEMP/{num}-meaning.jpg ./TEMP/{num}-full-{lang_code}.jpg ./TEMP/{num}-animation-{lang_code}.gif')
for i in range(START_RANGE, END_RANGE, 1):
makegif(i)
print(f"{lang_code} GIF flashcards made Successfully.")
print(f"Releasing {lang_code} GIF flashcards...")
files = glob.iglob(os.path.join("./TEMP/", "*.gif"))
for file in files:
if os.path.isfile(file):
shutil.copy2(file, RELEASE_DIR + "/Flash Card/")
os.remove(file)
print(f"{lang_code} GIF flashcards Released Successfully.")
def make_docx(lang_code: str = "fa", path: str = RELEASE_DIR + "/SQLite/Top 1000 Words in Gilaki.sqlite"):
language_name = "Farsi"
if lang_code == "en":
language_name = "English"
print(f"Making {language_name} DOCX started...")
document = Document("./templates/database.docx")
table = document.tables[0]
table.directions = WD_TABLE_DIRECTION.RTL
table.allow_autofit = True
row = table.rows[0].cells
row[0].text = ''
if lang_code == "fa":
row[0].paragraphs[0].add_run(f'مثال فارسی').bold = True
if lang_code == "en":
row[0].paragraphs[0].add_run(f'English Example').bold = True
row[0].paragraphs[0].alignment = WD_PARAGRAPH_ALIGNMENT.CENTER
row[0].vertical_alignment = WD_CELL_VERTICAL_ALIGNMENT.CENTER
row[1].text = ''
if lang_code == "fa":
row[1].paragraphs[0].add_run(f'کلمه فارسی').bold = True
if lang_code == "en":
row[1].paragraphs[0].add_run(f'English Word').bold = True
row[1].paragraphs[0].alignment = WD_PARAGRAPH_ALIGNMENT.CENTER
row[1].vertical_alignment = WD_CELL_VERTICAL_ALIGNMENT.CENTER
row[2].text = ''
if lang_code == "fa":
row[2].paragraphs[0].add_run('مثال گیلکی').bold = True
if lang_code == "en":
row[2].paragraphs[0].add_run('Gilaki Example').bold = True
row[2].paragraphs[0].alignment = WD_PARAGRAPH_ALIGNMENT.CENTER
row[2].vertical_alignment = WD_CELL_VERTICAL_ALIGNMENT.CENTER
row[3].text = ''
if lang_code == "fa":
row[3].paragraphs[0].add_run('کلمه گیلکی').bold = True
if lang_code == "en":
row[3].paragraphs[0].add_run('Gilaki Word').bold = True
row[3].paragraphs[0].alignment = WD_PARAGRAPH_ALIGNMENT.CENTER
row[3].vertical_alignment = WD_CELL_VERTICAL_ALIGNMENT.CENTER
try:
conn = sqlite3.connect(path)
cursor = conn.cursor()
sqlite_select_query = f"SELECT id, glk_word, glk_example, {lang_code}_word, {lang_code}_example from tbl_words"
cursor.execute(sqlite_select_query)
records = cursor.fetchall()
for r in records:
row = table.add_row().cells
row[0].text = ''
row[0].paragraphs[0].add_run(r[4])
row[0].paragraphs[0].alignment = WD_PARAGRAPH_ALIGNMENT.RIGHT
row[0].vertical_alignment = WD_CELL_VERTICAL_ALIGNMENT.CENTER
row[0].alignment = WD_TABLE_ALIGNMENT.RIGHT
row[1].text = ''
row[1].paragraphs[0].add_run(r[3])
row[1].paragraphs[0].alignment = WD_PARAGRAPH_ALIGNMENT.RIGHT
row[1].vertical_alignment = WD_CELL_VERTICAL_ALIGNMENT.CENTER
row[1].alignment = WD_TABLE_ALIGNMENT.RIGHT
row[2].text = ''
row[2].paragraphs[0].add_run(r[2])
row[2].paragraphs[0].alignment = WD_PARAGRAPH_ALIGNMENT.RIGHT
row[2].vertical_alignment = WD_CELL_VERTICAL_ALIGNMENT.CENTER
row[2].alignment = WD_TABLE_ALIGNMENT.RIGHT
row[3].text = ''
row[3].paragraphs[0].add_run(r[1])
row[3].paragraphs[0].alignment = WD_PARAGRAPH_ALIGNMENT.RIGHT
row[3].vertical_alignment = WD_CELL_VERTICAL_ALIGNMENT.CENTER
row[3].alignment = WD_TABLE_ALIGNMENT.RIGHT
cursor.close()
except sqlite3.Error as error:
print("Failed to read data from sqlite table", error)
finally:
if (conn):
conn.close()
print(f"{language_name} DOCX made Successfully.")
document.save(RELEASE_DIR + f"/Word/Top 1000 Words in Gilaki ({language_name}).docx")
def make_pdf(lang_code: str = "fa"):
language_name = "Farsi"
if lang_code == "en":
language_name = "English"
print(f"Making {language_name} PDF started...")
tmp_dir = RELEASE_DIR + f"/Word/Top 1000 Words in Gilaki ({language_name}).docx"
os.system(f'libreoffice --headless --convert-to pdf --outdir "{RELEASE_DIR}/PDF/" "{tmp_dir}"')
print(f"{language_name} PDF made Successfully.")
def make_xlsx(lang_code: str = "fa", path: str = RELEASE_DIR + "/SQLite/Top 1000 Words in Gilaki.sqlite"):
language_name = "Farsi"
if lang_code == "en":
language_name = "English"
print(f"Making {language_name} Excel started...")
sheet = pe.get_sheet(file_name=f"./templates/database{lang_code}.xlsx")
try:
conn = sqlite3.connect(path)
cursor = conn.cursor()
sqlite_select_query = f"SELECT id, glk_word, glk_example, {lang_code}_word, {lang_code}_example from tbl_words"
cursor.execute(sqlite_select_query)
records = cursor.fetchall()
for r in records:
sheet.row += [r[1], r[2], r[3], r[4]]
cursor.close()
sheet.rightToLeft = True
sheet.save_as(RELEASE_DIR + f"/Excel/Top 1000 Words in Gilaki ({language_name}).xlsx")
except sqlite3.Error as error:
print("Failed to read data from sqlite table", error)
finally:
if (conn):
conn.close()
print("XLSX made Successfully.")
def change_readme():
print("Updating README started...")
tmp_dir = "./templates/README.txt"
readme = readtemplate(tmp_dir)
d = datetime.now()
current_time = d.strftime('%d, %b %Y')
readme = readme.replace("{date}", f"{current_time}")
readme = readme.replace("{version}", f"{VERSION}")
f = open(RELEASE_DIR + "/README.md", "w")
f.write(readme)
f.close()
print("README updated Successfully.")
def push_release():
os.system(f'cd {RELEASE_DIR} && git add . && git commit -m "{COMMIT_MESSAGE}" && git push --force')
if __name__ == '__main__':
init()
normalize()
make_csv()
make_json()
update_docs()
make_xml()
make_docx("fa")
make_docx("en")
make_pdf("fa")
make_pdf("en")
make_xlsx("fa")
make_xlsx("en")
make_flash_html()
make_flash_jpg()
make_gif("fa")
make_gif("en")
change_readme()
push_release()