-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathflags.py
More file actions
34 lines (27 loc) · 989 Bytes
/
flags.py
File metadata and controls
34 lines (27 loc) · 989 Bytes
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
# This script generates the flags
# It must be run after the map.py script
import json
import requests
import subprocess
def main():
countries = {}
with open('resources/countries.json', 'r') as c:
countries = json.load(c)
flags = {}
for k in countries:
code = countries[k]['iso'].lower()
if k == 'SOL': code = 'somaliland'
elif k == 'KAS': code = 'pk-jk'
url = f"https://hatscripts.github.io/circle-flags/flags/{code}.svg"
response = requests.get(url)
if response.status_code != 200:
print("no", countries[k]['name'])
else:
with open("a.svg", mode="w") as file:
file.write(response.text)
subprocess.run(["convert", "-background", "none", "a.svg", f"assets/countries/{k}.png"])
flags[k] = response.text
with open('resources/flags.json', 'w', encoding='utf-8') as f:
json.dump(flags, f)
if __name__ == '__main__':
main()