-
Notifications
You must be signed in to change notification settings - Fork 1.9k
/
flags.py
39 lines (29 loc) · 969 Bytes
/
flags.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
import os
import json
flags_dir = os.path.join("flags", "1x1")
files = []
for (dirpath, dirnames, filenames) in os.walk(flags_dir):
files.extend(filenames)
break
file_codes = [name.replace(".svg", "") for name in files]
country_json = open("country.json")
flags = json.load(country_json)
flags.sort(key=lambda x: x["name"])
country_codes = [flag["code"] for flag in flags]
with open("country.json", "w", encoding='utf8') as output:
json.dump(flags, output, indent=2, sort_keys=True, ensure_ascii=False)
all_good = True
# Check if all files have names
for code in file_codes:
if code not in country_codes:
print("Code not found in country.json:", code)
all_good = False
# Check if all countries have files
for code in country_codes:
if code not in file_codes:
print("Flag icon not found for:", code)
all_good = False
if all_good:
print("All flag icons and country.json are in sync.")
exit(0)
exit(1)