[scripts] Add generate-readme script
This commit is contained in:
parent
bf61b88e2e
commit
c4c0102758
2 changed files with 77 additions and 0 deletions
26
.github/workflows/update_readme.yml
vendored
Normal file
26
.github/workflows/update_readme.yml
vendored
Normal file
|
@ -0,0 +1,26 @@
|
|||
name: update_readme
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: ["main"]
|
||||
|
||||
permissions:
|
||||
contents: write
|
||||
|
||||
jobs:
|
||||
update_readme:
|
||||
name: update readme
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- name: Generate readme
|
||||
run: python3 scripts/generate-readme.py > README.md
|
||||
- name: Commit and push
|
||||
run: |
|
||||
set -ex
|
||||
git config user.name 'github-actions[bot]'
|
||||
git config user.email 'github-actions[bot]@users.noreply.github.com'
|
||||
git add .
|
||||
if git commit -m 'Update README.md'; then
|
||||
git push
|
||||
fi
|
51
scripts/generate-readme.py
Normal file
51
scripts/generate-readme.py
Normal file
|
@ -0,0 +1,51 @@
|
|||
from datetime import date
|
||||
from pathlib import Path
|
||||
|
||||
names = {"rs": "Rust", "hs": "Haskell", "py": "Python", "apl": "APL"}
|
||||
exts = {"rs": ["rs"], "hs": ["hs"], "py": ["py", "ipynb"], "apl": ["ipynb"]}
|
||||
logos = {
|
||||
"rs": "https://rustacean.net/assets/rustacean-flat-noshadow.svg",
|
||||
"hs": "https://upload.wikimedia.org/wikipedia/commons/1/1c/Haskell-Logo.svg",
|
||||
"py": "https://upload.wikimedia.org/wikipedia/commons/c/c3/Python-logo-notext.svg",
|
||||
"apl": "https://aplwiki.com/images/thumb/c/c6/APL_logo.png/600px-APL_logo.png",
|
||||
}
|
||||
|
||||
|
||||
def link(year, day, lang):
|
||||
for ext in exts[lang]:
|
||||
if not Path(f"{names[lang]}/{year}/{day:02}.{ext}").exists():
|
||||
continue
|
||||
|
||||
return f' [<img height=12 src="{logos[lang]}">]({names[lang]}/{year}/{day:02}.{ext} "{names[lang]} solution for {year}/{day:02}")'
|
||||
|
||||
return ""
|
||||
|
||||
|
||||
print("# AdventOfCode")
|
||||
print(
|
||||
f"[Advent of Code](https://adventofcode.com/) solutions in {', '.join([*names.values()][:-1])} and {[*names.values()][-1]}"
|
||||
)
|
||||
|
||||
for year in range(2022, 2014, -1):
|
||||
print()
|
||||
print(f"## [{year}](https://adventofcode.com/{year})")
|
||||
print("|Mo|Tu|We|Th|Fr|Sa|Su|")
|
||||
print("|-|-|-|-|-|-|-|")
|
||||
|
||||
line = [""] * date(year, 12, 1).weekday()
|
||||
for day in range(1, 26):
|
||||
if len(line) == 7:
|
||||
print("|" + "|".join(line) + "|")
|
||||
line.clear()
|
||||
line.append(f"[**{day}**](https://adventofcode.com/{year}/day/{day})")
|
||||
for lang in names:
|
||||
line[-1] += link(year, day, lang)
|
||||
|
||||
for day in range(26, 32):
|
||||
if len(line) == 7:
|
||||
print("|" + "|".join(line) + "|")
|
||||
line.clear()
|
||||
line.append(f"{day}")
|
||||
|
||||
if line:
|
||||
print("|" + "|".join(line + [""] * (7 - len(line))) + "|")
|
Loading…
Add table
Add a link
Reference in a new issue