-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcountLessons.py
More file actions
54 lines (39 loc) · 1.21 KB
/
countLessons.py
File metadata and controls
54 lines (39 loc) · 1.21 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
import os
import json
latest_titles = {}
ROOT = "."
for lang in os.listdir(ROOT):
lesson_dir = os.path.join(ROOT, lang, "lessons")
if not os.path.isdir(lesson_dir):
continue
lessons = []
# collect (lesson_number, filename)
for file in os.listdir(lesson_dir):
if file.startswith("lesson") and file.endswith(".json"):
try:
n = int(file[len("lesson"):-5])
lessons.append((n, file))
except ValueError:
continue
if not lessons:
continue
# pick highest numeric lesson
n, latest_file = max(lessons, key=lambda x: x[0])
path = os.path.join(lesson_dir, latest_file)
try:
with open(path, "r") as f:
content = f.read().strip()
if not content:
print("Skipping empty file:", path)
continue
data = json.loads(content)
except json.JSONDecodeError:
print("Skipping invalid JSON:", path)
continue
latest_titles[lang] = {
"lesson": n,
"title": data.get("title", "Untitled")
}
# output
for lang, info in latest_titles.items():
print(f"{lang}: lesson {info['lesson']} - {info['title']}")