This repository has been archived by the owner on Oct 20, 2021. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
helpers.py
133 lines (106 loc) · 3.36 KB
/
helpers.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
import os
import subprocess
from app import app
import db
COVERS_DIR = os.path.join(app.static_folder, 'covers')
PDFS_DIR = os.path.join(app.static_folder, 'pdfs')
def init_db():
with app.app_context():
schema_file = os.path.join(app.root_path, 'db.schema')
schema = open(schema_file, 'r')
cur = db.get().cursor()
cur.executescript(schema.read())
schema.close()
cur.close()
db.get().commit()
def generate_db_issues_from_pdfs(year, month, day):
with app.app_context():
for pdf in os.listdir(PDFS_DIR):
number = pdf.split('.')[0]
date = '{}-{:02}-{:02}'.format(year, month, day)
db.query(
'INSERT INTO issues (number, date) VALUES (?, ?)',
(number, date)
)
if day == 15 and month == 12:
year += 1
if month == 1 or month == 8:
day = 1
month += 1
else:
if day == 15:
if month == 12:
month = 1
else:
month += 1
if day == 1:
day = 15
else:
day = 1
db.get().commit()
def generate_translations():
messages_pot_file_path = os.path.join(app.root_path, 'messages.pot')
translations_dir_path = os.path.join(app.root_path, 'translations')
sr_latn_rs_po_file_path = os.path.join(
messages_pot_file_path,
'sr_Latn_RS/LC_MESSAGES/messages.po'
)
subprocess.run([
'pybabel', 'extract',
'-F', 'babel.cfg',
'-o', messages_pot_file_path,
app.root_path
])
subprocess.run([
'pybabel', 'init',
'-l', 'sr_Latn_RS',
'-d', translations_dir_path,
'-i', messages_pot_file_path
])
subprocess.run([
'msgen',
'-i', messages_pot_file_path,
'-o', sr_latn_rs_po_file_path
])
with open(sr_latn_rs_po_file_path, 'r') as sr_latn_rs_po_file:
subprocess.run([
'msgfilter',
'-o', sr_latn_rs_po_file_path,
'recode-sr-latin'
], stdin=sr_latn_rs_po_file)
subprocess.run([
'pybabel', 'compile', '-f',
'-d', translations_dir_path
])
def generate_covers():
os.mkdir(COVERS_DIR)
pdfs_paths = os.listdir(PDFS_DIR)
for i, pdf_path in enumerate(pdfs_paths, start=1):
print('[{:>{}}/{}] Generating covers for {}...'.format(
i, len(str(len(pdfs_paths))), len(pdfs_paths), pdf_path
))
large_cover_path = '{}-large.png'.format(
os.path.join(COVERS_DIR, pdf_path.split('.')[0])
)
subprocess.run([
'convert',
'-density', '200',
'{}[0]'.format(os.path.join(PDFS_DIR, pdf_path)),
'-background', 'white',
'-flatten',
'-alpha', 'off',
'-resize', 'x1200',
'png24:{}'.format(large_cover_path)
])
subprocess.run([
'convert',
'-density', '200',
large_cover_path,
'-background', 'white',
'-flatten',
'-alpha', 'off',
'-resize', '250x',
'png24:{}-small.png'.format(
os.path.join(COVERS_DIR, pdf_path.split('.')[0])
)
])