Skip to content

Commit 719f9c6

Browse files
committed
scripts
1 parent 825c7be commit 719f9c6

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

scripts/extract_drawing.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,27 @@
2222
s = Path("~/.adventofcode.session").expanduser()
2323
if s.is_file():
2424
session = s.read_text().strip()
25-
calendar = requests.get(
25+
content = requests.get(
2626
f"https://adventofcode.com/{f}",
2727
headers={
2828
"Cookie": f"session={session}",
2929
"user-agent": "Mozilla/5.0",
3030
},
31-
).content.decode()
31+
).content
32+
33+
Path(f"{f}.html").write_bytes(content)
34+
35+
calendar = content.decode()
3236

3337

3438
def rgb(s: str) -> str:
35-
rgb = re.search(r"#([\da-f]+);", s).group(1)
39+
if "color:" not in s:
40+
return ""
41+
try:
42+
rgb = re.search(r"#([\da-f]+);", s).group(1)
43+
except:
44+
print("color problem:", s)
45+
exit(2)
3646
if len(rgb) == 3:
3747
if rgb == "ccc":
3848
rgb = "cccccc"
@@ -82,7 +92,7 @@ def rgb(s: str) -> str:
8292
b = line.find('<span class="calendar-day">')
8393
line = line[a:b]
8494

85-
line = re.sub(r'<span class="(.+?)">', lambda x: colors[x.group(1)], line)
95+
line = re.sub(r'<span class="(.+?)">', lambda x: colors.get(x.group(1), ""), line)
8696

8797
# line = re.sub(r"(<span.+?>)(.+?)(</span>)", lambda m: f"{rgb(m[1])}{m[2]}\033[0m", line)
8898
line = re.sub(r"(<span.+?>)(.+?)(</span>)", lambda m: "", line)

scripts/runall.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ def load_data(filter_year, filter_user, filter_yearday, with_answers):
308308
if filter_user == "me":
309309
if not user.isdigit():
310310
continue
311-
elif filter_user and user != filter_user and user != f"tmp-{filter_user}":
311+
elif filter_user and user != filter_user and user[: 4 + len(filter_user)] != f"tmp-{filter_user}":
312312
continue
313313

314314
year = int(input.parent.name)

0 commit comments

Comments
 (0)