Automatically submit solution

This commit is contained in:
Felix Bargfeldt 2023-11-30 12:39:57 +01:00
parent 3d19dd4f93
commit 21246a92de
Signed by: Defelo
GPG key ID: 2A05272471204DD3
3 changed files with 31 additions and 3 deletions

View file

@ -33,8 +33,14 @@ import numpy as np
import pyperclip
import z3
YEAR: int | None = None
DAY: int | None = None
def read_input(year: int, day: int, example: int | None = None) -> str:
global YEAR, DAY
YEAR = year
DAY = day
if example is None:
f = Path(__file__).parent / f"../../.cache/{year}/{day}"
else:
@ -45,3 +51,17 @@ def read_input(year: int, day: int, example: int | None = None) -> str:
def ans(answer):
print(answer)
pyperclip.copy(str(answer))
submit_part = input("\nSubmit solution? level=")
if submit_part in ["1", "2"] and YEAR is not None and DAY is not None:
import bs4
import requests
session = (Path(__file__).parent / f"../../.cache/session").read_text()
resp = requests.post(
f"https://adventofcode.com/{YEAR}/day/{DAY}/answer",
cookies={"session": session},
data={"level": submit_part, "answer": answer},
).text
bs = bs4.BeautifulSoup(resp, "html.parser")
print(bs.main.article.p.text)