Add function to populate data for Advent of Code

puzzle
This commit is contained in:
Jake Pullen
2023-12-06 08:02:02 +00:00
parent 853444ab75
commit 7ee2417313
+20 -3
View File
@@ -1,5 +1,6 @@
import os
import requests
from datetime import datetime
def get_puzzle_text(year, day):
url = f"https://adventofcode.com/{year}/day/{day}"
@@ -8,7 +9,8 @@ def get_puzzle_text(year, day):
return response.text
def get_puzzle_input(year, day):
session_cookie = ''
with open(r'advent_of_code/session_cookie.txt', 'r') as file:
session_cookie = file.read().strip()
url = f"https://adventofcode.com/{year}/day/{day}/input"
cookies = {'session': session_cookie}
response = requests.get(url, cookies=cookies)
@@ -39,11 +41,26 @@ def save_puzzle_input(year, day):
# Usage example
year = 2022
day = 7
current_year = datetime.now().year
current_day = datetime.now().day
def populate_data(year = current_year, day=current_day):
"""
Populates data for the Advent of Code puzzle.
requires a session cookie to be saved in advent_of_code/session_cookie.txt
Args:
year (int): The year of the Advent of Code puzzle. Defaults to the current year.
day (int): The day of the Advent of Code puzzle. Defaults to the current day.
Returns:
None
"""
save_puzzle_text(year, day)
save_puzzle_input(year, day)
populate_data()