2022-06-22 14:51:14 +02:00
|
|
|
import os
|
|
|
|
import json
|
|
|
|
|
|
|
|
dir_1x1 = os.path.join("flags", "1x1")
|
|
|
|
dir_4x3 = os.path.join("flags", "4x3")
|
|
|
|
|
|
|
|
files = []
|
|
|
|
for (dirpath, dirnames, filenames) in os.walk(dir_1x1):
|
|
|
|
files.extend(filenames)
|
|
|
|
break
|
|
|
|
|
|
|
|
|
|
|
|
def add_ids(directory):
|
2022-06-22 16:47:54 +02:00
|
|
|
for f in files:
|
|
|
|
filename = os.path.join(directory, f)
|
|
|
|
update = False
|
|
|
|
flag_id = "flag-icons-%s" % (f.replace(".svg", ""))
|
|
|
|
with open(filename, "r") as flag:
|
|
|
|
lines = flag.readlines()
|
|
|
|
if lines[0].find("id") == -1 and lines[0].find("viewBox") > 0:
|
|
|
|
lines[0] = lines[0].replace("viewBox", 'id="%s" viewBox' % flag_id)
|
|
|
|
update = True
|
2022-06-22 14:51:14 +02:00
|
|
|
|
2022-06-22 16:47:54 +02:00
|
|
|
if update:
|
|
|
|
print("Adding ID to", filename)
|
|
|
|
with open(filename, "w") as flag:
|
|
|
|
flag.writelines(lines)
|
2022-06-22 14:51:14 +02:00
|
|
|
|
|
|
|
|
|
|
|
add_ids(dir_1x1)
|
|
|
|
add_ids(dir_4x3)
|