-
Notifications
You must be signed in to change notification settings - Fork 0
/
aoc_test-data-extractor.py
61 lines (45 loc) · 2 KB
/
aoc_test-data-extractor.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
53
54
55
56
57
58
59
60
61
"""Created: 2023-02-08
Purpose: Extract the input data from the https://adventofcode.com website,
and store it in an easy machine readable file structure for the individual
solutions to read from. Used for testing code.
The online data have the following link structure:
https://adventofcode.com/20YY/day/DD/input
YY >= 15, in [15,<This Year>]
DD in [1,25]
"""
import requests
from pathlib import Path
get_input = False
repository_url = "https://github.com/VictorieeMan/Advent_Of_Code_Solutions"
newFileContent_base = "\"\"\"" + "Created: 2023-, by @VictorieeMan\n"
newFileContent_base = newFileContent_base + "Repository url: " + repository_url
with open("code_preamble.txt", 'r') as file:
code_preamble = file.read()
if(get_input):
session_uid = input("Cookie UID:")
session = requests.session()
session.cookies.set("session", session_uid, domain=".adventofcode.com")
base_url = "https://adventofcode.com/" # sample "https://adventofcode.com/2022/day/1/input"
days = range(10,26)
events = range(2015,2016)
for event in events:
for day in days:
if(get_input):
data_url = base_url + str(event) + "/" + "day" + "/" + str(day) + "/input"
request = session.get(data_url)
eventYY = str(event)
dayNN = str(day)
# Note the importance of this placement, before altering the dayNN below.
event_url = base_url + eventYY + "/day/" + dayNN
newFileContent = newFileContent_base + "\nEvent url: " + event_url +"\n\"\"\"\n" + code_preamble
if(day < 10):
dayNN = "0" + dayNN
path_uri = "events/" + str(event) + "/day" + dayNN
Path(path_uri).mkdir(parents=True, exist_ok=True)
if(get_input):
data_filename = path_uri + "/input.txt"
with open(data_filename,'wb') as file:
file.write(request.content)
solution_filename = path_uri + "/" + eventYY + "-" + dayNN + "-sol.py"
with open(solution_filename,'w') as file:
file.write(newFileContent)