-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathextract_anomaly_guides.py
60 lines (48 loc) · 1.28 KB
/
extract_anomaly_guides.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
60
#!/usr/bin/env python
import os
from datetime import datetime
from polib import POEntry, POFile
import requests
def main():
out_dir = os.path.join(
os.path.dirname(__file__), "anomaly_guides", "en", "LC_MESSAGES"
)
if not os.path.exists(out_dir):
os.makedirs(out_dir)
out_path = os.path.join(out_dir, "django.po")
po = POFile()
po.metadata = {
"Project-Id-Version": "hsreplaynet",
"Report-Msgid-Bugs-To": "",
"POT-Creation-Date": datetime.now().isoformat(),
"Last-Translator": "HearthSim <[email protected]>",
"Language-Team": "English",
"MIME-Version": "1.0",
"Content-Type": "text/plain; charset=utf-8",
"Content-Transfer-Encoding": "8bit",
}
r = requests.get("https://hsreplay.net/api/v1/battlegrounds/anomaly_guides/")
for anomaly_guide in r.json():
published_guide = anomaly_guide.get("published_guide", "")
anomaly_id = str(anomaly_guide.get("anomaly", ""))
guide_id = str(anomaly_guide.get("id", ""))
if not published_guide:
continue
entry = POEntry(
msgid=published_guide,
msgstr="",
occurrences=[
(
f"Anomaly id {anomaly_id} | Guide id {guide_id}"
, ""
),
]
)
if entry in po:
# duplicate
continue
po.append(entry)
po.save(out_path)
print(f"Written {out_path}")
if __name__ == "__main__":
main()