forked from aliftype/quran-data
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild_html.py
77 lines (71 loc) · 1.87 KB
/
build_html.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
import sys
import glob
from os import path
from jinja2 import Template
htmlTemplate = Template("""<html>
<head>
<meta charset="utf-8"/>
<title>{{name}}</title>
<style>
body {
direction: rtl;
text-align: justify;
text-align-last: center;
-moz-text-align-last: center;
width: 18em;
margin: auto;
font-family: Amiri Quran Colored;
font-size: 16pt;
}
.basmala {
font-size: 18pt;
text-align: center;
}
.sura-name {
font-family: Reem Kufi;
font-size: 24pt;
font-feature-settings: "cv01";
text-align: center;
}
</style>
</head>
<body>
<div class="sura-name">
سورة {{name}}\t{{place}}
</div>
{%- if basmala %}
<p class="basmala">﷽</p>
{% endif -%}
<p>
{{text}}
</p>
</body>
</html>
""")
def BuildPage(textfile, metadata):
text = textfile.read().strip()
num = int(path.splitext(path.basename(textfile.name))[0])
name, place, basmala = metadata[num]
html = htmlTemplate.render(text=text, name=name, place=place, basmala=basmala)
return html
def ReadMetadata(filename):
metadata = {}
with open(filename) as metafile:
lines = [l.strip().split("\t") for l in metafile.readlines()]
for num, line in enumerate(lines):
num = num + 1
metadata[num] = [line[0], line[1], True]
if len(line) == 3:
metadata[num][2] = False
return metadata
def main():
dirname = sys.argv[1]
filenames = glob.glob(dirname + "/???.txt")
metadata = ReadMetadata(dirname + "/meta.txt")
for filename in filenames:
with open(filename, "r") as textfile:
html = BuildPage(textfile, metadata)
with open(filename.replace(".txt", ".html"), "w") as htmlfile:
htmlfile.write(html)
if __name__ == "__main__":
main()