Created
November 16, 2021 19:15
-
-
Save MathisHammel/86b1e08c95d5d7c4c09e1e8e4bd5132f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
from aoc_secrets import AOC_COOKIE | |
YEAR = '2016' | |
def get_input(day): | |
req = requests.get(f'https://adventofcode.com/{YEAR}/day/{day}/input', headers={'cookie':'session='+AOC_COOKIE}) | |
return req.text | |
def get_example(day,offset=0): | |
req = requests.get(f'https://adventofcode.com/{YEAR}/day/{day}', headers={'cookie':'session='+AOC_COOKIE}) | |
return req.text.split('<pre><code>')[offset+1].split('</code></pre>')[0] | |
def submit(day, level, answer): | |
input(f'You are about to submit the follwing answer:\n>>>>>>>>>>>>>>>>> {answer}\nPress enter to continue or Ctrl+C to abort.') | |
data = { | |
'level': str(level), | |
'answer': str(answer) | |
} | |
response = requests.post(f'https://adventofcode.com/{YEAR}/day/{day}/answer', headers={'cookie':'session='+AOC_COOKIE}, data=data) | |
if 'You gave an answer too recently' in response.text: | |
print('VERDICT : TOO MANY REQUESTS') | |
elif 'not the right answer' in response.text: | |
if 'too low' in response.text: | |
print('VERDICT : WRONG (TOO LOW)') | |
elif 'too high' in response.text: | |
print('VERDICT : WRONG (TOO HIGH)') | |
else: | |
print('VERDICT : WRONG (UNKNOWN)') | |
elif 'seem to be solving the right level.' in response.text: | |
print('VERDICT : INVALID LEVEL') | |
else: | |
print('VERDICT : OK !') | |
DAY = 12 | |
s = get_input(DAY).strip() | |
submit(DAY, 1, ans) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment