-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathanki.py
More file actions
72 lines (68 loc) · 2.31 KB
/
anki.py
File metadata and controls
72 lines (68 loc) · 2.31 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import genanki
import unicodedata
import json
from pathlib import Path
deck = genanki.Deck(2069123839, "ΛΟΓΟΣ vocab")
model = genanki.Model(
2015670040,
"ΛΟΓΟΣ",
fields=[
{"name": "Greek"},
{"name": "English"},
{"name": "Part of Speech"},
],
css=""".card {
font-family: arial;
font-size: 20px;
text-align: center;
color: black;
background-color: white;
}""",
templates=[
{
"name": "Card 1",
"qfmt": "{{Greek}}<br>{{Part of Speech}}",
"afmt": '{{FrontSide}}<hr id="answer">{{English}}',
},
{
"name": "Card 2",
"qfmt": "{{English}}",
"afmt": '{{FrontSide}}<hr id="answer">{{Greek}}',
},
],
)
secs = {
'Ἐπίθετα': "Ἐπίθετον",
'Ἐπιφωνήματα': "Ἐπιφωνήμα",
'Ἐπιρρήματα': "Ἐπιρρήμα",
'Φράσεις': "Φράσις",
'Ἀριθμοί': "Ἀριθμός",
'Ὀνόματα': "Ὀνόμα",
'Ἐκφράσεις': "Ἐκφράσις",
'Ἀντωνυμίαι': "Ἀντωνυμία",
'Ῥήματα': "Ῥήμα",
'Ἄρθρον': "Ἄρθρον",
'Προθέσεις': "Προθέσις",
'Σύνδεσμοι': "Σύνδεσμος",
'Μόρια': "Μόριον"
}
for file in Path.cwd().glob("json/*.json"):
ch = file.stem.split(' ')[1]
data = json.loads(file.read_text(encoding="utf-8"))
for section in data["sections"]:
if section["section"].lower() == "κύρια ὀνόματα":
continue
pos = secs[section["section"]].lower()
for word in section["words"]:
greek = word["macronized"] if "macronized" in word else word["book_entry"]
greek = greek.replace("_","")
if greek[0].upper() == greek[0]:
# skip name-ish stuff
continue
if "gloss" not in word:
continue
gloss = word["gloss"]
greek = unicodedata.normalize("NFC", greek)
print(f"Adding {greek} {gloss} {pos}")
deck.add_note(genanki.Note(model=model, fields=[greek, gloss, pos], tags=[f"{ch}"]))
genanki.Package(deck).write_to_file("output.apkg")