Skip to content

Commit

Permalink
Script to update README in place (edent#765)
Browse files Browse the repository at this point in the history
* Modified and renamed script to update README in place

* Script fix and README update

* Misplaced quote in table fixed

* Removed old script

* Readme update
  • Loading branch information
jmb authored Oct 9, 2023
1 parent 70f4abc commit ef7c4a7
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 27 deletions.
6 changes: 3 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@ This is the standard guideline. Use this to help with sizing your icons and they

## Edit Readme

You will need to generate a new table for the README. To do this, run:
You will need to update the README. To do this, run:

`python3 generate_readme_table.py`
`python3 update_readme.py`

Copy the output and paste it over the old table.
This will update the average file size at the top of the file as well as regenerate the table of icons.

## Reference Image

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Super Tiny Icons

Under 1KB each! Super Tiny Web Icons are minuscule SVG versions of your favourite logos. The average size is _under_ 521 bytes!
Under 1KB each! Super Tiny Web Icons are minuscule SVG versions of your favourite logos. There are currently 363 icons and the average size is _under_ 519 bytes!

The logos have a 512x512 viewbox, they will fit in a circle with radius 256. They will scale up and down to suit your needs.

Expand Down
23 changes: 0 additions & 23 deletions generate_readme_table.py

This file was deleted.

47 changes: 47 additions & 0 deletions update_readme.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
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 = "<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)
f.truncate()

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

0 comments on commit ef7c4a7

Please sign in to comment.