-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinputs.py
52 lines (47 loc) · 1.64 KB
/
inputs.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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import requests
import sys
import os
import shutil
day = int(sys.argv[1])
try:
os.mkdir(f'day{day:02}')
except FileExistsError:
pass
if not os.path.isfile(f'day{day:02}/day{day:02}.py'):
shutil.copyfile('dayx.py', f'day{day:02}/day{day:02}.py')
shutil.copyfile('testinput.txt', f'day{day:02}/input.txt')
inpCount = 3
for i in range(2,inpCount):
shutil.copyfile('testinput.txt', f'day{day:02}/input{i}.txt')
go = '''
GGGGGGGGGGGGG OOOOOOOOO
GGG::::::::::::G OO:::::::::OO
GG:::::::::::::::G OO:::::::::::::OO
G:::::GGGGGGGG::::G O:::::::OOO:::::::O
G:::::G GGGGGG O::::::O O::::::O
G:::::G O:::::O O:::::O
G:::::G O:::::O O:::::O
G:::::G GGGGGGGGGG O:::::O O:::::O
G:::::G G::::::::G O:::::O O:::::O
G:::::G GGGGG::::G O:::::O O:::::O
G:::::G G::::G O:::::O O:::::O
G:::::G G::::G O::::::O O::::::O
G:::::GGGGGGGG::::G O:::::::OOO:::::::O
GG:::::::::::::::G OO:::::::::::::OO
GGG::::::GGG:::G OO:::::::::OO
GGGGGG GGGG OOOOOOOOO
'''
with open('auth', 'r') as auth:
cookies = {'session': auth.read()}
print('Enter to fetch input ', end='')
while True:
input()
inp = requests.get(f'https://adventofcode.com/2018/day/{day}/input', cookies=cookies)
if inp.status_code != 200:
print(f'{inp.status_code}, retry on enter')
else:
print('200, saving file!')
print(go)
with open(f'day{day:02}/input.txt', 'wb') as f:
f.write(inp.content)
break