-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAoCUtilsDenz.py
More file actions
119 lines (95 loc) · 3.97 KB
/
Copy pathAoCUtilsDenz.py
File metadata and controls
119 lines (95 loc) · 3.97 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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
import os
import requests
from bs4 import BeautifulSoup
def BoilerPlate(SesssionCookie):
"""
Setup for the Boilerplate code with Inputs and Questions automatically filled in,
Using the session-id to login and get all info.
"""
year_dir = [year for year in range(2015, 2022)]
day_dir = [f"Day{day}" for day in range(26)]
files_dir = ["%Input.txt", "%Part1.py", "%Part2.py", "%Ques.txt", "README_%.md"]
main_dir = "AdventOfCode"
i = 0
Part1_Counter = 0
Part2_Counter = 0
for year in year_dir:
for day in day_dir:
if i > 25:
i = 0
if Part1_Counter > 25:
Part1_Counter = 0
if Part2_Counter > 25:
Part2_Counter = 0
for file in files_dir:
req_file = f"{main_dir}/{year}/{day}/{file.replace('%',day)}"
path = f"{main_dir}/{year}/{day}"
if not os.path.exists(path):
os.makedirs(path)
with open(os.path.join(path, file.replace("%", day)), "w+") as f:
# Inputs
if f.name.endswith("Input.txt"):
InputUrl = f"https://adventofcode.com/{year}/day/{i}"
print(InputUrl)
cookie = {"Cookie": SesssionCookie}
InputText = requests.get(InputUrl + "/input",headers=cookie)
InputTextQues = requests.get(
InputUrl, headers=cookie
)
ErrorMsg = "please don't repeatedly request this endpoint before it unlocks! the calendar countdown is synchronized with the server time; the link will be enabled on the calendar the instant this puzzle becomes available."
NotFoundMsg = "404 not found"
if NotFoundMsg in str(InputText.text).lower():
print("This puzzle doesnt exist")
pass
elif ErrorMsg in str(InputText.text).lower():
print("This Input is not unlocked yet")
return
else:
f.write(InputText.text)
i += 1
# BoilerPlateCode
if f.name.endswith("Part1.py"):
if Part1_Counter == 0:
Part1_Counter += 1
pass
else:
BoilerPlateCode = """
#Part 1 of Day%
import time
StartTime = time.time()
InputFileLines = open('Day%Input.txt').readlines()
#Code
FinalAnswer =
EndTime = time.time()
print(f"Final score: {FinalAnswer}")
print(f'Execution Time: {EndTime - StartTime}')
"""
f.write(BoilerPlateCode.replace("%", str(Part1_Counter)))
Part1_Counter += 1
# BoilerPlateCode
if f.name.endswith("Part2.py"):
if Part2_Counter == 0:
Part2_Counter += 1
pass
else:
BoilerPlateCode = """
#Part 2 Day%
import time
StartTime = time.time()
InputFileLines = open('Day%Input.txt').readlines()
#Code
FinalAnswer =
EndTime = time.time()
print(f"Final score: {FinalAnswer}")
print(f'Execution Time: {EndTime - StartTime}')
"""
f.write(BoilerPlateCode.replace("%", str(Part2_Counter)))
Part2_Counter += 1
if f.name.endswith("Ques.txt"):
InputContent = InputTextQues.text
InputSoup = BeautifulSoup(InputContent)
try:
text = str(InputSoup.body.main.article.text)
f.write(text)
except Exception as e:
print(e)