Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Script update for references and checks #799

Merged
merged 8 commits into from
Sep 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
396 changes: 396 additions & 0 deletions CHECK.html

Large diffs are not rendered by default.

744 changes: 372 additions & 372 deletions README.md

Large diffs are not rendered by default.

383 changes: 383 additions & 0 deletions REFERENCE.md

Large diffs are not rendered by default.

File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
165 changes: 126 additions & 39 deletions update_readme.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,46 +2,133 @@
import xml.etree.ElementTree as ET
import re

table_length = 6
counter = 0
table_columns = 6

svg_list = sorted(os.listdir('images/svg/'))
svg_list = sorted(os.listdir("images/svg/"))
ref_list = sorted(os.listdir("images/reference/"))
svg_data = {}
total_bytes = 0

table = "<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 += "<tr>\n"

table += f"<td>{name}<br>"
table += f"<img src=\"https://edent.github.io/SuperTinyIcons/images/svg/{svg}\" width=\"100\" title=\"{name}\"><br>"
table += f"{bytes} bytes</td>\n"

counter +=1

if counter == 6 :
table += "</tr>\n\n"
counter = 0

if counter != 0 :
table += "</tr>\n\n"

table += "</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>.*?</table>", 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)
for svg_file in svg_list:
if not svg_file.endswith(".svg"):
continue
svg = svg_file.split(".")[0]
svg_data[svg] = {"svg_file": svg_file}
svg_data[svg]["name"] = (
ET.parse(f"images/svg/{svg_file}").getroot().attrib["aria-label"]
)
bytes = os.stat(f"images/svg/{svg_file}").st_size
svg_data[svg]["bytes"] = bytes
total_bytes += bytes

for ref_file in ref_list:
if ref_file.endswith(".md"):
continue
ref_name = ref_file.split(".")[0]
if ref_name in svg_data:
svg_data[ref_name]["ref_file"] = ref_file


with open("images/reference/index.md", "r") as f:
file = f.read()
match = re.findall(
r"images/svg/(\w+)\.svg.*?\|.*?src=\".*?([\w.]+)\".*\|\ *(.*)\n",
file,
re.MULTILINE,
)
if match:
for svg, ref_file, source in match:
svg_data[svg]["source"] = source
if "ref_file" not in svg_data[svg]:
svg_data[svg]["ref_file"] = ref_file


readme_table = "<table>\n"
check_table = '<table style="1px solid #dfe2e5;"><tr><th>SVG Icon</th><th>SVG Icon<br/>with border=50%</th><th>Reference Image</th><th>Source</th></tr>\n'
reference_table = "-|-|-\n"
missing_table = "&nbsp; | ** No Reference Image Found ** | &nbsp;\n"

counter = 0
for svg in svg_data:
svg_file = svg_data[svg]["svg_file"]
name = svg_data[svg]["name"]
bytes = svg_data[svg]["bytes"]

check_table += f'<tr><td><img src="images/svg/{svg_file}" width="100" /></td><td><img src="images/svg/{svg_file}" width="100" style="border-radius: 50%;"></td>'

if "ref_file" in svg_data[svg]:
ref_file = svg_data[svg]["ref_file"]
reference_table += f'<img src="images/svg/{svg_file}" width="256" /> | <img src="images/reference/{ref_file}" width="256"> | '
check_table += f'<td><img src="images/reference/{ref_file}" width="100"></td>'

if "source" in svg_data[svg]:
source = svg_data[svg]["source"]
reference_table += source
check_table += f"<td>{source}</td>"

reference_table += "\n"
else:
missing_table += f'<img src="images/svg/{svg_file}" width="256" /> | {name} <br/>*[{svg}]* | \n'

check_table += "</tr>\n"

if counter == 0:
readme_table += "<tr>\n"

readme_table += f"<td>{name}<br>"
readme_table += f'<img src="images/svg/{svg_file}" width="100" title="{name}"><br>'
readme_table += f"{bytes} bytes</td>\n"

counter += 1

if counter == table_columns:
readme_table += "</tr>\n\n"
counter = 0

if counter != 0:
readme_table += "</tr>\n\n"

readme_table += "</table>"
check_table += "</table>"


readme_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>.*?</table>", readme_table, file)
file = re.sub(
r"There are currently \d* icons and the average size is _under_ \d* bytes\!",
readme_summary_text,
file,
)

f.seek(0)
f.write(file)
f.truncate()

print(f"README.md updated with {len(svg_list)} icons.")

print(f"README.md updated with {len(svg_list)} icons.")

with open("REFERENCE.md", "r+") as f:
file = f.read()

file = re.sub(r"(?s)-\|-\|-.*", reference_table, file)
file += missing_table

f.seek(0)
f.write(file)
f.truncate()

print(f"REFERENCE.md updated.")

with open("CHECK.html", "r+") as f:
file = f.read()

file = re.sub(r"(?s)<table>.*?</table>", check_table, file)

f.seek(0)
f.write(file)
f.truncate()

print(f"CHECK.html updated.")
Loading