Skip to main content

Get your puzzle data with a single import

Project description

pyversions pypi womm travis

Get your puzzle data with a single import statement:

from aocd import data

Might be useful for lazy Pythonistas and speedhackers.

Note: Please use version 0.3+ of this library. It memoizes successful requests client side and rate-limits the get_data function, as requested by the AoC author. Thanks!

Automated submission

New in version 0.4.0. Basic use:

from aocd import submit
submit(my_answer, level=1, day=25, year=2017)

Note that the same filename introspection of year/day also works for automated submission. There’s also introspection of the “level”, i.e. part 1 or part 2, aocd can automatically determine if you have already completed part 1 or not, and submit an answer for the correct part accordingly. In this case, just use:

from aocd import submit
submit(my_answer)

The response message from AoC will be printed in the terminal. If you gave the right answer, then the puzzle will be refreshed in your web browser (so you can read the instructions for the next part, for example). Proceed with caution! If you submit wrong guesses, your user WILL get rate-limited by Eric, so don’t call submit until you’re fairly confident you have a correct answer!

Setup Guide

Install with pip

pip install advent-of-code-data

Puzzle inputs differ by user. So export your session ID, for example:

export AOC_SESSION=cafef00db01dfaceba5eba11deadbeef

This is a cookie which is set when you login to AoC. You can find it with your browser inspector. If you’re hacking on AoC at all you probably already know these kind of tricks, but if you need help with that part then you can look here.

Note: If you don’t like the env var, you could also put into a text file in your home directory (use the filename ~/.config/aocd/token).

How does it work?

It will automatically get today’s data at import time, if used within the interactive interpreter. Otherwise, the date is found by introspection of the path and file name from which aocd module was imported.

This means your filenames should be something sensible. The examples below should all parse correctly, because they have digits in the path that are unambiguously recognisable as AoC years (2015+) or days (1-25).

q03.py
xmas_problem_2016_25b_dawg.py
~/src/aoc/2015/p8.py

A filename like problem_one.py will not work, so don’t do that. If you don’t like weird frame hacks, just use the aocd.get_data() function instead and have a nice day!

>>> from aocd import get_data
>>> get_data(day=2)
'UULDRRRDDLRLURUUURUURDRUURRDRRURUD...
>>> get_data(day=24, year=2015)
'1\n2\n3\n7\n11\n13\n17\n19\n23\n31...

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

advent_of_code_data-0.7.1-py2.py3-none-any.whl (8.8 kB view details)

Uploaded Python 2Python 3

File details

Details for the file advent_of_code_data-0.7.1-py2.py3-none-any.whl.

File metadata

  • Download URL: advent_of_code_data-0.7.1-py2.py3-none-any.whl
  • Upload date:
  • Size: 8.8 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.21.0 setuptools/40.6.3 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.7.0

File hashes

Hashes for advent_of_code_data-0.7.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 f1ffa157c4b86f3c50ca5af7c1f5bff5394fb1a7198d36fddd66bb7134591fff
MD5 343e9a0d82912a9260c68d82c678f30e
BLAKE2b-256 bbab4a72f56676f934a3a078be379510b2807271ec57bd1a89d46df3df85128e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page