2021-10-22 22:26:29 +02:00
|
|
|
import os
|
|
|
|
import json
|
|
|
|
|
2021-10-23 10:43:06 +02:00
|
|
|
flags_dir = os.path.join("flags", "1x1")
|
2021-10-22 22:26:29 +02:00
|
|
|
|
2021-10-23 11:15:03 +02:00
|
|
|
files = []
|
2021-10-22 22:26:29 +02:00
|
|
|
for (dirpath, dirnames, filenames) in os.walk(flags_dir):
|
2021-10-23 11:15:03 +02:00
|
|
|
files.extend(filenames)
|
2021-10-22 22:26:29 +02:00
|
|
|
break
|
|
|
|
|
2021-10-23 11:31:02 +02:00
|
|
|
file_codes = [name.replace(".svg", "") for name in files]
|
2021-10-22 22:26:29 +02:00
|
|
|
|
|
|
|
country_json = open("country.json")
|
|
|
|
flags = json.load(country_json)
|
2022-08-24 19:38:07 +02:00
|
|
|
flags.sort(key=lambda x: x["name"])
|
2021-10-23 11:31:02 +02:00
|
|
|
country_codes = [flag["code"] for flag in flags]
|
2021-10-22 22:26:29 +02:00
|
|
|
|
2022-08-24 19:38:07 +02:00
|
|
|
with open("country.json", "w", encoding='utf8') as output:
|
|
|
|
json.dump(flags, output, indent=2, sort_keys=True, ensure_ascii=False)
|
2021-10-23 10:43:06 +02:00
|
|
|
|
|
|
|
all_good = True
|
|
|
|
|
2021-10-23 11:31:02 +02:00
|
|
|
# Check if all files have names
|
2021-10-23 11:15:03 +02:00
|
|
|
for code in file_codes:
|
2021-10-23 11:31:02 +02:00
|
|
|
if code not in country_codes:
|
|
|
|
print("Code not found in country.json:", code)
|
|
|
|
all_good = False
|
2021-10-23 10:43:06 +02:00
|
|
|
|
2021-10-23 11:15:03 +02:00
|
|
|
# Check if all countries have files
|
|
|
|
for code in country_codes:
|
2021-10-23 11:31:02 +02:00
|
|
|
if code not in file_codes:
|
|
|
|
print("Flag icon not found for:", code)
|
|
|
|
all_good = False
|
2021-10-23 10:43:06 +02:00
|
|
|
|
|
|
|
|
|
|
|
if all_good:
|
2021-10-23 11:31:02 +02:00
|
|
|
print("All flag icons and country.json are in sync.")
|
2022-06-21 09:52:19 +02:00
|
|
|
exit(0)
|
|
|
|
exit(1)
|