-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
59 lines (48 loc) · 2.1 KB
/
main.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
import json
from pathlib import Path
from traceback import format_exc
from html_writer import get_html_task, LOG
from tex import get_tex_years
def main() -> None:
dir_root = Path(__file__).parent.resolve()
years = list(get_tex_years(dir_root.joinpath('seminar-till-2014').resolve()))
dir_output = dir_root.joinpath('output').resolve()
for year in years:
for wave in year.waves:
for task in wave.tasks:
# noinspection PyBroadException
ksi_task_dir = dir_output.joinpath(f"{year.first_year}").joinpath(f"{wave.index}").joinpath(
f"{task.index}")
file_assigment = ksi_task_dir.joinpath('assigment.html')
file_solution = ksi_task_dir.joinpath('solution.html')
file_meta = ksi_task_dir.joinpath('info.json')
print(f"{ksi_task_dir.relative_to(dir_root)}", end=' ... ', flush=True)
if ksi_task_dir.exists():
print('skip')
continue
try:
ksi_task = get_html_task(task)
except KeyboardInterrupt:
print(LOG.text)
return
except Exception:
print('ERROR')
file_traceback = dir_root.joinpath(f"error_convert_{year.first_year}_{wave.index}_{task.index}.log")
with file_traceback.open('w') as f:
f.write(''.join(format_exc()))
continue
ksi_task_dir.mkdir(parents=True, exist_ok=True)
with file_assigment.open('w') as f:
f.write(ksi_task.assigment)
with file_solution.open('w') as f:
f.write(ksi_task.solution)
with file_meta.open('w') as f:
json.dump({
'title': ksi_task.title,
'points': ksi_task.points
}, f, indent=True)
print('OK')
# return
print(LOG.unknown_commands)
if __name__ == '__main__':
main()