Last active
April 12, 2019 04:02
-
-
Save vict0rsch/223858dd409865e0816f8824b003cce8 to your computer and use it in GitHub Desktop.
Produce shields from settings.yml to include as images into Readme.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from pathlib import Path | |
if __name__ == "__main__": | |
labels_path = Path() / "labels.yml" | |
if labels_path.exists(): | |
with labels_path.open() as f: | |
lines = f.readlines() | |
shields = [] | |
names = [] | |
i = 1 | |
while i < len(lines): | |
l = lines[i] | |
if " - name" in l: | |
name = l.split("name:")[-1].strip().replace('"', "") | |
color = lines[i + 1].split("color:")[-1].strip() | |
shields.append( | |
f"https://img.shields.io/badge/{name}-{color}.svg".replace( | |
" ", "%20" | |
) | |
) | |
names.append(name) | |
i += 2 | |
else: | |
i += 1 | |
shields_lines = sorted(list(f"[{n}]: {s}" for n, s in zip(names, shields))) | |
with open(Path() / "shields.txt", "w") as f: | |
f.write("\n".join(shields_lines)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Following up on https://gist.github.com/Vict0rSch/188a60f1e87a68844e41082583df64c4
From:
produces:
to use as:
![][CLA Signed] ![][stale] ![][difficulty: impossible] etc.
: etc.