-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdate_comic_files_from_diff.py
More file actions
38 lines (34 loc) · 1.24 KB
/
Copy pathupdate_comic_files_from_diff.py
File metadata and controls
38 lines (34 loc) · 1.24 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
#!/usr/bin/env python3
# -*- coding:utf-8 -*-
"""
Update comic files using new files and old files generated by generate_comic_files.py
This script writes to local_files/new_comic_files.json
"""
import json
import os
file_names = [
"catagory_pages.json",
"chapter_pages.json",
"section_pages.json",
"comic_pages.json",
]
with open(
os.path.join("local_files", "new_comic_files.json"), "w", encoding="utf-8"
) as fo:
new_json_data = {}
for file_name in file_names:
assert os.path.exists(os.path.join("tracking_files", file_name))
new_data = json.load(open(os.path.join("tracking_files", file_name)))
if os.path.exists(os.path.join("local_files", "old_" + file_name)):
old_data = json.load(open(os.path.join("local_files", "old_" + file_name)))
for k, v in new_data.items():
if k not in old_data:
new_json_data[k] = v
else:
different = False
assert type(v) is dict and type(old_data[k]) is dict
if v != old_data[k]:
new_json_data[k] = v
else:
new_json_data.update(new_data)
json.dump(new_json_data, fo, ensure_ascii=False, indent=4)