Add personal stats to README
This commit is contained in:
parent
9cd865e194
commit
64a0dac5a6
3 changed files with 51 additions and 15 deletions
6
.github/README.md
vendored
6
.github/README.md
vendored
|
@ -50,6 +50,12 @@ Puzzle inputs and descriptions are not included in this repository. You'll have
|
|||
|
||||
_(Boilerplate code and code that generates visualisations is not included)_
|
||||
|
||||
---
|
||||
|
||||
<!-- RANK START -->
|
||||
|
||||
<!-- RANK END -->
|
||||
|
||||
[check]: https://github.com/codemicro/adventOfCode/blob/master/.github/check.png?raw=true
|
||||
[cross]: https://github.com/codemicro/adventOfCode/blob/master/.github/cross.png?raw=true
|
||||
[partial]: https://github.com/codemicro/adventOfCode/blob/master/.github/partial.png?raw=true
|
||||
|
|
51
.github/tablegen.py
vendored
51
.github/tablegen.py
vendored
|
@ -1,24 +1,29 @@
|
|||
from datetime import datetime
|
||||
import re
|
||||
import sys
|
||||
from bs4 import BeautifulSoup
|
||||
import requests
|
||||
|
||||
today_day = datetime.now().day
|
||||
|
||||
readme_text = open(sys.argv[1]).read().strip().split("\n")
|
||||
|
||||
start_flag = "<!-- PARSE START -->"
|
||||
end_flag = "<!-- PARSE END -->"
|
||||
table_start_flag = "<!-- PARSE START -->"
|
||||
table_end_flag = "<!-- PARSE END -->"
|
||||
|
||||
rank_start_flag = "<!-- RANK START -->"
|
||||
rank_end_flag = "<!-- RANK END -->"
|
||||
|
||||
table_lines = []
|
||||
in_table = False
|
||||
for line in readme_text:
|
||||
line = line.strip()
|
||||
|
||||
if line == end_flag:
|
||||
if line == table_end_flag:
|
||||
in_table = False
|
||||
if in_table:
|
||||
table_lines.append(line)
|
||||
elif line == start_flag:
|
||||
elif line == table_start_flag:
|
||||
in_table = True
|
||||
|
||||
for i, l in enumerate(table_lines):
|
||||
|
@ -27,16 +32,38 @@ for i, l in enumerate(table_lines):
|
|||
|
||||
table_lines[i] = f"| {today_day} | ![Not yet attempted][pending] | | |"
|
||||
|
||||
counter = 0
|
||||
rank_lines = "### Personal day-by-day stats\n\n```".split("\n")
|
||||
r = requests.get("https://adventofcode.com/2020/leaderboard/self", cookies={"session": sys.argv[2]})
|
||||
soup = BeautifulSoup(r.text, features="html.parser")
|
||||
rank_lines += soup.find("article").get_text().split("and 0 otherwise.")[-1].strip("\n").split("\n")
|
||||
rank_lines += ["```"]
|
||||
|
||||
in_rank = False
|
||||
table_appended = False
|
||||
rank_appended = False
|
||||
output = []
|
||||
for i, line in enumerate(readme_text):
|
||||
line = line.strip()
|
||||
|
||||
if line == end_flag:
|
||||
in_table = False
|
||||
if in_table:
|
||||
readme_text[i] = table_lines[counter]
|
||||
counter += 1
|
||||
elif line == start_flag:
|
||||
if line == table_start_flag:
|
||||
in_table = True
|
||||
output.append(table_start_flag)
|
||||
for ln in table_lines:
|
||||
output.append(ln)
|
||||
if line == table_end_flag:
|
||||
in_table = False
|
||||
|
||||
open(sys.argv[1], "w").write("\n".join(readme_text))
|
||||
if line == rank_start_flag:
|
||||
in_rank = True
|
||||
output.append(rank_start_flag)
|
||||
for ln in rank_lines:
|
||||
output.append(ln)
|
||||
if line == rank_end_flag:
|
||||
in_rank = False
|
||||
|
||||
if in_rank or in_table:
|
||||
continue
|
||||
|
||||
output.append(line)
|
||||
|
||||
open(sys.argv[1], "w").write("\n".join(output))
|
||||
|
|
9
.github/workflows/updatetable.yml
vendored
9
.github/workflows/updatetable.yml
vendored
|
@ -1,4 +1,4 @@
|
|||
name: Update table
|
||||
name: Update README
|
||||
|
||||
on:
|
||||
workflow_dispatch:
|
||||
|
@ -20,12 +20,15 @@ jobs:
|
|||
with:
|
||||
python-version: '3.x'
|
||||
|
||||
- name: Install Python dependencies
|
||||
run: pip install beautifulsoup4 requests
|
||||
|
||||
- name: Run script
|
||||
run: python .github/tablegen.py .github/README.md
|
||||
run: python .github/tablegen.py .github/README.md ${{ secrets.AOC_SESSION }}
|
||||
|
||||
- name: Prettify markdown
|
||||
uses: creyD/prettier_action@v3.1
|
||||
with:
|
||||
prettier_options: --write .github/README.md
|
||||
# dry: True
|
||||
commit_message: "Update table"
|
||||
commit_message: "Update README"
|
Loading…
Add table
Add a link
Reference in a new issue