-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathget_input.py
More file actions
43 lines (31 loc) · 1.23 KB
/
get_input.py
File metadata and controls
43 lines (31 loc) · 1.23 KB
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
import requests, os.path
import datetime
def get_day(day):
return '0' + day if int(day) < 10 else day
def get_input_for_day(session, day):
day_for_folder = get_day(day)
year = str(datetime.date.today().year)
with open('.session') as session_file:
session = session_file.read()
directory = 'Day' + day_for_folder
input_file_path = directory + '/input.txt'
if not os.path.exists(input_file_path):
if not os.path.exists(directory):
os.makedirs(directory)
cookies = {
'session': session,
}
response = requests.get('https://adventofcode.com/' + year + '/day/'+ day + '/input', cookies=cookies)
with open(input_file_path, 'w') as input_file:
content = response.content.decode()
input_file.write(content.rstrip())
return content.split('\n')
else:
with open(input_file_path) as input_file:
return input_file.read().rstrip().split('\n')
def get_test_input_for_day(day):
day_for_folder = get_day(day)
directory = 'Day' + day_for_folder
input_file_path = directory + '/test_input.txt'
with open(input_file_path) as input_file:
return input_file.read().rstrip().split('\n')