-
Notifications
You must be signed in to change notification settings - Fork 0
/
newDay.py
38 lines (28 loc) · 1.38 KB
/
newDay.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
import configparser
import os
import re
import shutil
import requests as requests
config = configparser.ConfigParser()
config.read('config.ini')
folder = config['general']['year'] + " - " + config['general']['language']
os.makedirs(os.path.join('.', folder), exist_ok=True)
completedDays = next(os.walk(os.path.join('.', folder)))[1]
completedDays.sort(key=lambda f: int(re.sub(r'\D', '', f)))
if len(completedDays) > 0:
dayNum = int(completedDays[-1].split(" ")[-1]) + 1
else:
dayNum = 1
if dayNum > 25:
print("There are only 25 challenges in "+config['general']['year']+". Make sure the year is right in config.ini")
exit(1)
response = requests.get("https://adventofcode.com/"+config['general']['year']+"/day/"+str(dayNum)+"/input", cookies={"session": config['general']['sessionID']})
if "unlocks" not in response.text:
os.mkdir(os.path.join(folder, f"Day {dayNum:02d}"))
with open(os.path.join(folder, f"Day {dayNum:02d}", "input.txt"), "w") as inputFile:
inputFile.write(response.text)
with open(os.path.join(folder, f"Day {dayNum:02d}", "testInput.txt"), "w") as testInputFile:
testInputFile.write("")
shutil.copyfile(os.path.join(folder, "template."+config['general']['extension']), os.path.join(folder, f"Day {dayNum:02d}", f"Day{dayNum:02d}.{config['general']['extension']}"))
else:
print("please wait until the challenge has unlocked")