forked from obsgolem/LOGOSTools
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjson_to_md.py
More file actions
31 lines (28 loc) · 1.12 KB
/
json_to_md.py
File metadata and controls
31 lines (28 loc) · 1.12 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
import json
from pathlib import Path
import unicodedata
"""
Converts the JSON documents to markdown for easier human consumption
"""
out_dir = Path.cwd() / "generated_markdown"
out_dir.mkdir(exist_ok=True)
for file in Path.cwd().glob("json/*.json"):
with file.open() as f:
data = json.load(f)
with (out_dir / f"{file.stem} {data['chapter_name']}.md").open("w") as f:
print(f"Pg. {data['word_list_page_number']} ", file=f)
print(
f"Ex. {data['exercise_page_range'][0]}-{data['exercise_page_range'][1]} ",
file=f,
)
for section in data["sections"]:
print(f"# {unicodedata.normalize('NFC', section['section'])} ", file=f)
for word in section["words"]:
line = ""
if "first_occurrence" in word:
line = f" | First appeared on line {word['first_occurrence'][0]}"
word = (
word["macronized"] if "macronized" in word else word["book_entry"]
)
word = unicodedata.normalize("NFC", word)
print(f"{word}{line} ", file=f)