forked from l0o0/translators_CN
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmetadata.py
33 lines (27 loc) · 1.04 KB
/
metadata.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
import json
import os
from datetime import datetime
with open("data/data.json", encoding='utf-8') as handle:
mapDict = json.load(handle)
def read_metadata(filename):
try:
with open(filename, encoding='utf-8') as handle:
headers = [next(handle) for x in range(13)]
return json.loads(''.join(headers))
except json.decoder.JSONDecodeError:
print("Parsing Error: " + filename)
return ""
translators = os.listdir(".")
translators = [t for t in translators if t.endswith('js') and t not in ['RefWorks Tagged.js', 'BibTeX.js']]
translators = sorted(translators)
translator_metadata = {}
for t in translators:
metadata = read_metadata("./" + t)
if metadata:
translator_metadata[t] = {
'label': mapDict.get(metadata['label'], metadata['label']),
'lastUpdated': metadata['lastUpdated']
}
with open("data/translators.json", 'w', encoding='utf-8') as handle:
print(translator_metadata)
json.dump(translator_metadata, handle, ensure_ascii=False, indent=4)