import os
import xml.etree.ElementTree as ET
import re
table_length = 6
counter = 0
svg_list = sorted(os.listdir('images/svg/'))
total_bytes = 0
table = "
\n"
for svg in svg_list:
name = ET.parse('images/svg/'+svg).getroot().attrib["aria-label"]
bytes = os.stat('images/svg/'+svg).st_size
total_bytes += bytes
if counter == 0 :
table += "\n"
table += f"{name} "
table += f" "
table += f"{bytes} bytes | \n"
counter +=1
if counter == 6 :
table += "
\n\n"
counter = 0
if counter != 0 :
table += "\n\n"
table += "
"
summary_text = f"There are currently {len(svg_list)} icons and the average size is _under_ {round(total_bytes / len(svg_list))} bytes!"
with open('README.md','r+') as f:
file = f.read()
file = re.sub(r"(?s)", table, file)
file = re.sub("There are currently \d* icons and the average size is _under_ \d* bytes\!", summary_text, file)
f.seek(0)
f.write(file)
f.truncate()
print(f"README.md updated with {len(svg_list)} icons.")