Skip to content

Instantly share code, notes, and snippets.

@mrisoli
Last active Dec 23, 2020
Embed
What would you like to do?
import os
import datetime
from botocore.vendored import requests
LEADERBOARD_URL = "https://adventofcode.com/{}/leaderboard/private/view/{}".format(
os.environ.get('YEAR'), os.environ.get('LEADERBOARD_ID'))
def lambda_handler(event, context):
timestamp = (datetime.datetime.now() - datetime.timedelta(minutes=15)).timestamp()
r = requests.get(
"{}.json".format(LEADERBOARD_URL),
cookies={"session": os.environ.get('COOKIE')}
)
if r.status_code != requests.codes.ok:
print("Error retrieving leaderboard")
sys.exit(1)
j = r.json()
result = {}
for m in j["members"].items():
data = m[1]
name = data["name"]
completion_day_level = data["completion_day_level"]
puzzle_completions = []
for day,completions in completion_day_level.items():
for pp in completions.items():
star_part, star_ts = pp
star_ts = int(star_ts["get_star_ts"])
if star_timestamp > timestamp:
puzzle_completions.append((day,star_part))
if puzzle_completions:
result[name] = puzzle_completions
if result:
text = ""
for person, puzzles in result.items():
puzzles_map = [("day " + day + " part " + part) for (day, part) in puzzles]
puzzles_str = ", ".join(puzzles_map)
text += person + " has earned " + str(len(puzzles)) + " :star: for solving puzzles " + puzzles_str + "\n"
requests.post(os.environ.get('SLACK_WEBHOOK_URL'), json={"text": text})
else:
print("No new solutions posted")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment