-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcustoms.py
More file actions
29 lines (26 loc) · 838 Bytes
/
Copy pathcustoms.py
File metadata and controls
29 lines (26 loc) · 838 Bytes
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
import typer
import requests
import os
app = typer.Typer()
@app.command()
def getday(day:int):
if not os.path.exists('cookie.txt'):
open("cookie.txt", 'w').close()
cookief = open("cookie.txt", 'r+')
token = cookief.read()
if not token:
print("Session cookie not found, to set it simply write it into the just created cookie.txt")
exit()
if not os.path.exists('inputs'):
os.makedirs('inputs')
with requests.Session() as s:
s.cookies.set("session", token, domain=".adventofcode.com")
data = s.get(f"https://adventofcode.com/2021/day/{day}/input")
with open(f"inputs/{day}.txt", 'w') as fd:
fd.write(data.text)
print(f"{day}.txt created")
@app.command()
def foo():
print("yeah that's useless lol")
if __name__ == "__main__":
app()