wimglenn / advent-of-code-data Goto Github PK
View Code? Open in Web Editor NEWGet your Advent of Code data with a single import statement
License: MIT License
Get your Advent of Code data with a single import statement
License: MIT License
Is it possible to suppress stdout when using the aoc
runner? The output from print statements tends to destroy the runner output.
Thanks for providing this library!
I just downloaded the source code and tried running the test suite with
python3 -m pytest .
and got a lot of errors like this:
def test_attribute_errors_have_context():
> with pytest.raises(AttributeError("nope")):
E TypeError: 'AttributeError' object is not iterable
I haven't looked into why this happens, but I guess that you rely on some older version of Python or pytest than what I'm running:EDIT: I see now that you run Python 3.11 + pytest 7.2.0... Maybe it's some other dependency that I got messed up.
$ python3 --version
Python 3.9.2
$ python3 -m pip show pytest
Name: pytest
Version: 7.2.0
...
Modifying the tests with this ugly regex fixes most of the issues:
sed -i -z -E "s/(\s+)with pytest\.raises\((.+)\(\"?([^\"]+)\"?\)\):\n([^\n]+)/\1with pytest\.raises\(\2\) as exc_info:\n\4\1assert \"\3\" == str\(exc_info\.value\)/" ./**/*.py
we're getting more and more windows users..
actually / still works for windows paths, but the output looks a little weird up in logging - mixture of \ and / in paths
remove any hardcoded / path seps
advent-of-code-data/aocd/get.py
Line 135 in b948c34
I mean, I suppose it will still work and match files named "2021/02.py", it'll just match that 2 rather than 02, but I don't see why that assertion exists?
More of a question than an issue, as I realised while writing this that zero-padded filenames will still work
recently (2021 day 6 and 2021 day 7) there have been inputs that are single line numeric lists eg: 1,2,3,4,5
This API doesn't currently have a quick way of parsing this data.
I would suggest the following modification to the aocd.transforms.numbers
function to keep the old behavior but also allow quick parsing of numeric lists with arbitrary separators.
_missing = object()
def numbers(data, sep=_missing):
if sep is _missing:
return [int(n) for n in data.splitlines()]
else:
return [int(n.strip()) for n in data.strip().split(sep)]
eg:
>>> from aocd.transforms import numbers
>>> data = "1\n2\n3\n4\n5"
>>> numbers(data) # current behavior
[1, 2, 3, 4, 5]
>>> data = "1,2,3,4,5"
>>> numbers(data, sep=',') # new behavior (single char)
[1, 2, 3, 4, 5]
>>> data = '1hello2hello3hello4hello5'
>>> numbers(data, sep='hello') # new behavior (multi char)
[1, 2, 3, 4, 5]
>>> data = "1 2 3\n 4 \t 5"
>>> numbers(data, sep=None) # new behavior (whitespace)
[1, 2, 3, 4, 5]
Hi there,
I've been using aocd with a simple from aocd import data
in the past. However, this year, that fails with AocdError: Failed introspection of day
-- even though I did not change the structure of the filename.
Now, I did a tiny bit of digging, and it seems the problem is in get_day_and_year()
which finds a stack frame like
stack crawl found /var/folders/mc/tp4bg6ld1_38smzn0c6xpwmh0000gn/T/ipykernel_2298/3755599408.py
which it clearly can't extract the current date from :)
It seems to me that this is the last stack frame to consider, if I add something like 'ipyk' in name
to the reasons_to_skip_frame
it jumps into the REPL branch.
I suspect (but did not verify) that this is to do with the version of ipython/jupyter-lab I'm running?
For reference that is
Happy to assist if there's anything more I can do to debug the issue :)
Thanks!
Atreju
Hi, I have been using submit function from this package for this years version of Advent of Code.
When I submit the second day using a normal call to the function, I get an unexpected response.
submit(solution, part="b", day=2, year=2023)
>>> coerced int64 value 86036 for 2023/02
I have thus far only seen this for the second day, part b. For the other day, and parts I get no such response. It doesn't break functionality, but may be unintended?
This would be very useful as I am using the runner to run all the solutions with GitHub actions and would like the build to fail if any of the solutions broke during the run.
import aocd
results in AttributeError. Is that intended?
When you submit a wrong answer sometimes you get back some information like "your answer was too high" or "your answer was too low". AOCD should remember this info, and refuse to submit subsequent answers if we know they are incorrect in light of this information.
Used network inspector in chrome to identify my token (I use my github login) for Advent 2021.
I also used the 'aocd-token' script. This returned the same value as the network inspector.
Saved it (on windows 10) my ~.config\aocd\token file.
aocd.data
returns:
DeadTokenError: the auth token ...89f2 is expired or not functioning
It's seeing the correct token value that I put in the config file.
What might I be doing wrong here?
Hi,
Having completed all the days from the Advent of Code, the multiple different inputs feature seems really interesting and fun. I am trying to get the "Verify your code against multiple different inputs" feature working on Windows 8.1 in a cmd.exe, but am getting stuck with errors.
Output:
``
Microsoft Windows [Version 6.3.9600]
(c) 2013 Microsoft Corporation. All rights reserved.
C:\Windows\System32>aoc --years 2019 --day 1
22.01s 2019/1 - The Tyranny of the Rocket Equation wim/google /RuntimeError: I/O operations still in flight while destroying Overlapped object, the process may crash
22.11s 2019/1 - The Tyranny of the Rocket Equation wim/google N ImportError("Error while finding module specificat
0.41s 2019/1 - The Tyranny of the Rocket Equation wim/github -RuntimeError: I/O operations still in flight while destroying Overlapped object, the process may crash
0.51s 2019/1 - The Tyranny of the Rocket Equation wim/github N ImportError("Error while finding module specificat
0.99s 2019/1 - The Tyranny of the Rocket Equation myusername/google -RuntimeError: I/O operations still in flight while destroying Overlapped object, the process may crash
1.09s 2019/1 - The Tyranny of the Rocket Equation myusername/google ? part a: 1234 (correct answer is unknown) ? part b: 5678 (correct answer is unknown)
0.39s 2019/1 - The Tyranny of the Rocket Equation myusername/github /RuntimeError: I/O operations still in flight while destroying Overlapped object, the process may crash
0.49s 2019/1 - The Tyranny of the Rocket Equation myusername/github N part a: 1234 (expected: 3305115) N part b: 5678 (expected: 4954799)
`
My Actions to this point:
Install Latest advent-of-code module: pip install advent-of-code-data --upgrade
Create tokens file with github and google at: {USER}.config\aocd\tokens.json
Install sample master: pip install advent-of-code-sample (Identical issue is caused when I download the folder from github then do pip install {PATH_TO_SAMPLE_MASTER}
Install the wimcode: pip install advent-of-code-wim
Launch cmd.exe with admin privileges and run: aoc --years 2019 --days 1
I'm running Python 3.5. Let me know if you'd like any other information. Thanks for your time in reading this.
I keep needing these so...
from aocd import data # string
from aocd import lines # list
from aocd import numbers # list or array of numbers
Hi! Is there a chance that this library could also get the example data?
Errors with incorrect auth occurs because uri does not use HTTPS for its protocol.
Messages always returned the prompt, rather than the proper response, this was fixed for me upon changing uri to utilize https.
I'd make a pull request but honestly a one-liner doesn't really need that kind of attention.
Please don't make modules like this. This module requests the user's input every time the script runs; the Advent of Code servers aren't magic and can only handle limited capacity. Please make your script store the player's input in a file and possibly sleep() before downloading the input to prevent someone calling get_data() in a loop.
See also: https://www.reddit.com/r/adventofcode/comments/3v64sb/aoc_is_fragile_please_be_gentle/
An extra dependency to browsercookie
could let users use aocd without having to export their session manually.
This is what I've been using before I discovered this package:
import requests, browsercookie # from the pypi packages of the same names
def get_input(day):
return requests.get(
f"https://adventofcode.com/2020/day/{day}/input",
cookies=browsercookie.firefox()
).text
Would you be interested in integrating this ?
I think easter_eggs
is the last Puzzle
property that always triggers a request against the site -- it's probably worth caching it.
I don't think this is particularly urgent (and if you don't get a chance to get to it I'm happy to put a PR together :) )
Thanks for the super-handy library! It's been fun integrating it into my workflow this year.
I have trouble installing the package with pip :
Config :
Steps to reproduces :
pyenv local 3.9.13
python -m venv .venv
source .venv/bin/activate
pip install advent-of-code-data -i https://pypi.org/pypi
Logs :
Looking in indexes: https://pypi.org/pypi
Collecting advent-of-code-data
Using cached advent_of_code_data-1.2.0-py2.py3-none-any.whl (24 kB)
Collecting tzlocal
Using cached tzlocal-4.2-py3-none-any.whl (19 kB)
Collecting beautifulsoup4
Using cached beautifulsoup4-4.11.1-py3-none-any.whl (128 kB)
Collecting termcolor
Using cached termcolor-2.1.0-py3-none-any.whl (5.8 kB)
Collecting pebble
Using cached Pebble-5.0.3-py3-none-any.whl (30 kB)
Collecting python-dateutil
Using cached python_dateutil-2.8.2-py2.py3-none-any.whl (247 kB)
Collecting requests
Using cached requests-2.28.1-py3-none-any.whl (62 kB)
Collecting soupsieve>1.2
Using cached soupsieve-2.3.2.post1-py3-none-any.whl (37 kB)
Collecting six>=1.5
Using cached six-1.16.0-py2.py3-none-any.whl (11 kB)
Collecting idna<4,>=2.5
Using cached idna-3.4-py3-none-any.whl (61 kB)
Collecting urllib3<1.27,>=1.21.1
Using cached urllib3-1.26.12-py2.py3-none-any.whl (140 kB)
INFO: pip is looking at multiple versions of python-dateutil to determine which version is compatible with other requirements. This could take a while.
INFO: pip is looking at multiple versions of pebble to determine which version is compatible with other requirements. This could take a while.
INFO: pip is looking at multiple versions of <Python from Requires-Python> to determine which version is compatible with other requirements. This could take a while.
INFO: pip is looking at multiple versions of beautifulsoup4 to determine which version is compatible with other requirements. This could take a while.
INFO: pip is looking at multiple versions of advent-of-code-data to determine which version is compatible with other requirements. This could take a while.
ERROR: Could not find a version that satisfies the requirement charset-normalizer<3,>=2 (from requests) (from versions: 3.0.0)
ERROR: No matching distribution found for charset-normalizer<3,>=2
Does someone have the same issue ? Any Workaround ?
I don't know why, but at some point in the last few days the Puzzle class broke for me.
If I run the script at https://github.com/jolitti/adventofcode/blob/main/2022/day16.py (both with aocd version 1.3.1 and 1.3.2) it just prints the description of the problem to the terminal without attempting to submit the solution.
Has the aoc API changed lately?
To help keep clean directories, is it possible to add a separate env variable for the location of the tokens.json file? This would allow a user to use separate directories for configuration and data.
It looks like this should just be one change in the runner, I'm happy to raise a PR?
use https://adventofcode.com/settings to get user id
So that we can mention the auth method e.g.
# ~/.config/aocd/token
627c421d1ff2f493a34f6468b99521ff2... # github/wimglenn
this occurrence is almost surely due to user error (re-running a script with the submit call in it by accident)
Using r = submit(100, part='b', day=12, year=2016)
just returns the description of the puzzle, it doesn't appear to submit an answer.
It looks like the message returned when submitting is now just the puzzle description for some reason
When the runner gives an error on a specific input, I would like to be able to switch to work on that quickly. The way I'm doing it currently is by adding user=User(token=) to the Puzzle constructor. However, this could be made much cleaner if it supported the identifiers in tokens.json. This would also mean the cookie token will not likely appear in code that is sent to github.
This is a Feature Request:
currently I need to know what the data looks like before I can write my import statement.
For example, today (2021-12-02) doing
from aocd import numbers
gives me a ValueError
because the import can't be parsed as numbers
.
What I'd like is something like from aocd import parsed_data
which would go through the different parsers in some pre-defined order (strongest to weakest, ie currently numbers, then lines, then raw data), and return the first one that can parse the data successfully.
For the life of me I can't get this working.
Here's what I've tried:
from aocd import data
print(data)
Directory for all examples is ~/code/by-language/python/3/adventofcode/2017/13. With a directory like that, you'd think any filename would work, right? Wrong. Here are the filenames I've tried.
All print None. What should I do?
I'd like to use this library within a jupyter notebook. As part of that, I'd like to be able to programmatically pull in my AOC_SESSION
from a previous cell.
I'd like to stay within my notebook rather than running the cookies cli separately.
If the extraction logic were exposed in cookies.py
, I could run a function like def extract_tokens()
to make everything explicit and I could pass my session directly.
While scrape_session_tokens()
is an exposed function, it does too much (argparse
especially) that makes it incompatible with the notebook.
I gotta do things outside of the notebook :/
Since the move from requests to urllib3 the proxy settings appear not to be observed.
This could be fixed by using urllib3.ProxyManager instead of urllib3.PoolManager in utils.py
Currently, after something is submitted, the response is printed onto the terminal. However, in scripting, getting this response is not convenient, and the submit
function returns None
.
Is there any way AoCD can be modified to return the response, so it can be used in scripting, etc.?
Thanks
When I do a submit, I get a RESPONSE OK but nothing actually happens, and I still need to submit manually on the site. I was submitting the correct answers. Was this feature disabled for some reason? I see some indication of that in the other issue threads.
apparently %-I
doesn't work on Windows ๐
add a windows pull request builder, perhaps move this to github actions and off travis..
An answer was rejected when send through aocd, when using a float (w/o siginificant digits behind comma) as an input, while it was accepted afterwards from the website, with an int as an input, with the same value. AFAIK, AoC never had any non-whole numbers as the answer in the past?
Expected behaviour:
An int is sent to the website, rather than the float
Potential solution:
Idk how to best catch this unexpected behaviour.
Should the library always send an int? Or do input typecheck on top of valuecheck and give a warning?Maybe change a float answer with mod(X,1)==0 (no significant digits behind comma) to INT?
Same behaviour for other days 15/'21, for example part B:
was accepted
if you need more info, let me know.
(& kudos for the amazing library!)
pip install advent-of-code-data
~/.config/aocd/token
aocd 13 2018 > day13.txt
A file named day13.txt
is created with the contents of https://adventofcode.com/2018/day/13/input
An empty file named day13.txt
is created and the following error is output in the terminal:
Traceback (most recent call last):
File "/Users/junefish/.pyenv/versions/3.11.6/bin/aocd", line 8, in <module>
sys.exit(main())
^^^^^^
File "/Users/junefish/.pyenv/versions/3.11.6/lib/python3.11/site-packages/aocd/cli.py", line 114, in main
data = get_data(session=session, day=args.day, year=args.year)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/junefish/.pyenv/versions/3.11.6/lib/python3.11/site-packages/aocd/get.py", line 37, in get_data
puzzle = Puzzle(year=year, day=day, user=user)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/junefish/.pyenv/versions/3.11.6/lib/python3.11/site-packages/aocd/models.py", line 189, in __init__
pre = self.user.memo_dir / f"{self.year}_{self.day:02d}"
^^^^^^^^^^^^^^^^^^
File "/Users/junefish/.pyenv/versions/3.11.6/lib/python3.11/site-packages/aocd/models.py", line 97, in memo_dir
return AOCD_DATA_DIR / self.id
^^^^^^^
File "/Users/junefish/.pyenv/versions/3.11.6/lib/python3.11/site-packages/aocd/models.py", line 77, in id
owner = get_owner(self.token)
^^^^^^^^^^^^^^^^^^^^^
File "/Users/junefish/.pyenv/versions/3.11.6/lib/python3.11/site-packages/aocd/utils.py", line 147, in get_owner
raise DeadTokenError(f"the auth token ...{token[-4:]} is dead")
aocd.exceptions.DeadTokenError: the auth token ...cef6 is dead
Here's my request headers (with session cookie partially redacted for privacy, but I'm copying and pasting the whole thing):
If I run cat ~/.config/aocd/token
I get (except not redacted) AOC_SESSION=53616...cef6
it looks like the original project is alive again.
~/.config/aocd/token
, log that we are doing that.browsercookie appears to have safari support (test it) safari support is b0rked, and doesn't work on windows/chrome ("win32crypt must be available to decrypt Chrome cookie on Windows")
browser-cookie3 got the windows chrome support (borisbabic/browser_cookie3#48) but appears not to work reliably on Linux (it needs to check in Profile */Cookies
and not just Default/Cookies
).
maybe we use both?!
When behind proxy aocd can't download anything from the website.
File "C:\Users\x\AppData\Roaming\Python\Python310\site-packages\requests\sessions.py", line 529, in request
resp = self.send(prep, **send_kwargs)
File "C:\Users\x\AppData\Roaming\Python\Python310\site-packages\requests\sessions.py", line 645, in send
r = adapter.send(request, **kwargs)
File "C:\Users\x\AppData\Roaming\Python\Python310\site-packages\requests\adapters.py", line 513, in send
raise ProxyError(e, request=request)
requests.exceptions.ProxyError: HTTPSConnectionPool(host='adventofcode.com', port=443): Max retries exceeded with url: /settings (Caused by ProxyError('Cannot connect to proxy.', OSError('Tunnel connection failed: 407 Proxy Authentication Required')))
The source of the https://adventofcode.com/{year}/leaderboard/self
does not include an article
tag which causes an exception:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/jokajak/.cache/pypoetry/virtualenvs/aoc-coTrba3t-py3.10/lib/python3.10/site-packages/aocd/models.py", line 113, in get_stats
if soup.article.pre is None and "overall leaderboard" in soup.article.text:
AttributeError: 'NoneType' object has no attribute 'pre'
Working on AoC 2022, day 7. The actual example_data is:
$ cd /
$ ls
dir a
14848514 b.txt
8504156 c.dat
dir d
$ cd a
$ ls
dir e
29116 f
2557 g
62596 h.lst
$ cd e
$ ls
584 i
$ cd ..
$ cd ..
$ cd d
$ ls
4060174 j
8033020 d.log
5626152 d.ext
7214296 k
but aocd thinks it is:
$ system-update --please --pretty-please-with-sugar-on-top
Error: No space left on device
I guess you're just scraping the webpage for the first <\code> tags... It would be nice if there was a way to either be smarter about it, or maybe allow us to get at all example code fragments through aocd...
I installed this module on python3.10 with pip and get_data
works correctly, but Puzzle
(along with lines
and numbers
) is not recognized as part of the module. What could be causing this error?
I'm seeing a lot of traffic generated by User-Agent advent-of-code-data v0.9.8
, which I assume is this project. Could you make it so requests are throttled (maybe one every few seconds) regardless of the type of request? For example, I see a lot of same-second requests for puzzle text, input data, and answer submission.
When setting the session id through an env var (export AOC_SESSION=โฆ
), running aocd
yielded the following exception:
$ aocd
Traceback (most recent call last):
File "/home/mhm/code/advent-of-code/.venv/bin/aocd", line 8, in <module>
sys.exit(main())
File "/home/mhm/code/advent-of-code/.venv/lib/python3.9/site-packages/aocd/cli.py", line 50, in main
data = get_data(day=args.day, year=args.year)
File "/home/mhm/code/advent-of-code/.venv/lib/python3.9/site-packages/aocd/get.py", line 40, in get_data
puzzle = Puzzle(year=year, day=day, user=user)
File "/home/mhm/code/advent-of-code/.venv/lib/python3.9/site-packages/aocd/models.py", line 162, in __init__
prefix = os.path.join(self.user.memo_dir, fname)
File "/home/mhm/code/advent-of-code/.venv/lib/python3.9/site-packages/aocd/models.py", line 85, in memo_dir
return os.path.join(AOCD_DATA_DIR, self.id)
File "/home/mhm/code/advent-of-code/.venv/lib/python3.9/site-packages/aocd/models.py", line 72, in id
with open(fname, "w") as f:
FileNotFoundError: [Errno 2] No such file or directory: '/home/mhm/.config/aocd/token2id.json'
It worked when I dumped the session id into ~/.config/aocd/token
.
from aocd import chunks
for chunk in chunks:
...
should be equivalent to
from aocd import data
for chunk in data.split("\n\n"):
...
After running aocd 2022 5 --example
I got
unable to find example data for 2022/05 (MaxRetryError("HTTPSConnectionPool(host='adventofcode.com', port=443): Max retries exceeded with url: /2022/day/5 (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:997)')))"))
no examples available for 2022/05
but I remember it worked last year
Version is aocd v2.0.1
Running on MacOS 14.0
I've found these useful:
@property
def answered_a(self):
return bool(getattr(self, "answer_a", None))
@property
def answered_b(self):
return bool(getattr(self, "answer_b", None))
def answered(self, part):
if part == "a":
return bool(getattr(self, "answer_a", None))
if part == "b":
return bool(getattr(self, "answer_b", None))
raise AttributeError
Thanks for the helpful tool!
(I'd submit these as a pull request but I've run out of cycles getting pytest to run clean; I'm missing a plugin and I can't figure out which.)
AoC server meltdown on day 1, 2020. Maybe this lib should catch 503 exceptions and delay/retry a few times..
I've installed your package with pip install advent-of-code-data
but I don't seem to have the aoc
and aocd
commands available in my PATH. Is there something I need to do to allow running these commands? I'm not sure where to find them. Thanks!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.