-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathextract_comp_guides.py
More file actions
71 lines (57 loc) · 1.88 KB
/
extract_comp_guides.py
File metadata and controls
71 lines (57 loc) · 1.88 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/usr/bin/env python
import os
import re
from datetime import datetime
from polib import POEntry, POFile
import requests
def main():
out_dir = os.path.join(
os.path.dirname(__file__), "comp_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().strftime("%Y-%m-%d %H:%M%z"),
"Last-Translator": "HearthSim <admin@hearthsim.net>",
"Language-Team": "English",
"Language": "en",
"MIME-Version": "1.0",
"Content-Type": "text/plain; charset=utf-8",
"Content-Transfer-Encoding": "8bit",
}
r = requests.get("https://hsreplay.net/api/v1/battlegrounds/comp_guides/")
r.raise_for_status()
for comp in r.json():
comp_id = str(comp.get('id', ''))
fields_to_process = {
'name': 'name',
'how_to_play': 'how_to_play',
'when_to_commit': 'when_to_commit',
'common_enablers': 'common_enablers',
'summary': 'summary'
}
for field, context_name in fields_to_process.items():
content = comp.get(field, '')
if not content:
continue
fullname = str(comp.get("name", ""))
entry = POEntry(
msgid=content,
msgstr="",
occurrences=[
(
f"{field} | https://hsreplay.net/battlegrounds/comps/{comp_id}/"
, ""
),
]
)
if entry not in po:
po.append(entry)
po.save(out_path)
print(f"Written {out_path}")
if __name__ == "__main__":
main()