-
Notifications
You must be signed in to change notification settings - Fork 0
/
helper.py
31 lines (23 loc) · 1.02 KB
/
helper.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
import os
import requests
def getInput(day: int):
filename = 'input/day{0}.txt'.format(day)
if (not os.path.exists(filename)):
download(day, filename)
lines = open(filename).readlines()
return [s.strip() for s in lines]
def download(day: int, target: str):
if not os.path.exists('input'):
os.mkdir('input')
url = 'https://adventofcode.com/2015/day/{0}/input'.format(day)
print("Download: " + url)
headers = { 'User-Agent': 'https://github.com/frankivo/adventofcode [email protected]' }
cookies = { 'session': os.environ["AOC_COOKIE"] }
response = requests.get(url, headers=headers, cookies = cookies)
if (response.status_code != 200):
raise Exception("Download failed: " + response.status_code)
open(target, 'wb').write(response.content)
def slice(data) -> list:
return [data[i:i+2] for i in range(0, len(data), 1)]
def grouped(data, size) -> list:
return [data[i:i+size] for i in range(0, len(data), size)]