-
Notifications
You must be signed in to change notification settings - Fork 4
/
extract_archetype_info.py
executable file
·53 lines (42 loc) · 1.1 KB
/
extract_archetype_info.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
#!/usr/bin/env python
import os
from datetime import datetime
import requests
from polib import POEntry, POFile
def main():
out_dir = os.path.join(
os.path.dirname(__file__), "archetypes", "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 <admin@hearthsim.net>",
"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/archetypes/")
for archetype in r.json():
name = archetype.get("name", "")
url = archetype.get("url", "")
if not name or not url:
continue
entry = POEntry(
msgid=name,
msgstr="",
occurrences=[("https://hsreplay.net" + url, "")]
)
if entry in po:
# duplicate
continue
po.append(entry)
po.save(out_path)
print(f"Written {out_path}")
if __name__ == "__main__":
main()