Skip to content

Instantly share code, notes, and snippets.

@MathisHammel
Created December 1, 2022 08:52
Show Gist options
  • Star 11 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MathisHammel/0e0e55fcf682086af7d3cd2f66d4a31e to your computer and use it in GitHub Desktop.
Save MathisHammel/0e0e55fcf682086af7d3cd2f66d4a31e to your computer and use it in GitHub Desktop.
# Advent of Code template by @MathisHammel
import requests
from aoc_secrets import AOC_COOKIE # Put your session cookie in this variable
YEAR = '2022'
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 !')
def ints(s):
return list(map(int, s.split()))
DAY = 1
PART = 1
s = get_input(DAY).strip()
import collections
import math
#import networkx as nx
# Your code here
ans = 123456
submit(DAY, PART, ans)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment