-
Notifications
You must be signed in to change notification settings - Fork 0
/
gen.py
executable file
·61 lines (53 loc) · 1.75 KB
/
gen.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/usr/bin/env python3.12
import sys
import os
import requests
filename = "solution.py"
input_file = "input.txt"
day = sys.argv[1]
session = ""
print(f"Preparing Day {day}")
try:
with open(".cli_env/session", "r") as f:
session = f.read()
except Exception as _:
print("Grab your session Cookie, and put in the .cli_env/session file.")
try:
os.mkdir(day)
except Exception as _:
pass
if not os.path.exists(os.path.join(day, filename)):
with open(os.path.join(day, filename), "w") as f:
f.write(f'lines = open("{input_file}", "r").readlines()\n')
else:
print(f"{filename} already exists")
if not os.path.exists(os.path.join(day, input_file)):
try:
with open(os.path.join(day, input_file), "w") as f:
url = f"https://adventofcode.com/2023/day/{day}/input"
inputs = requests.get(url, headers={"Cookie": f"session={session}"}).text
f.write(f"{inputs}")
except Exception as e:
print(e)
sys.exit(0)
else:
print(f"{input_file} already exists")
print("Updating README")
percentage = int(day) * 4
readme = f"""# <img src="https://adventofcode.com/favicon.png" width=24 alt=":star:"> Advent of Code 2023
[![AOC](https://img.shields.io/badge/solved-{percentage}%25-00cc00?labelColor=0f0f23)](https://adventofcode.com/2023/)
Advent of Code :snake: Python 3.12 Solutions.
<table>
<thead>
{"\n".join(f" <th> <a href='https://adventofcode.com/2023/day/{d}'>{d}</a></th>" for d in range(1, 26))}
</thead>
<tbody>
<tr>
{"\n".join(f" <td> <a href='{d:02}/{filename}'>🌟🌟</a></td>" for d in range(1, int(day) + 1))}
{"\n".join(" <td> <a href='#'>☆☆</a></td>" for d in range(1, 25 - int(day) + 1))}
</tr>
</tbody>
</table>
"""
with open("README.md", "w") as f:
f.write(readme)