Helper package to interact with the Advent of Code website programmatically through JavaScript
npm install aoc-helper---
I take no responsibility if you submit wrong answers or get timed out.
This does not mean that it doesn't work, it just means that I am not
responsible if anything happens by misuse. I use this personally, and
it works for me, so I decided to clean it up and share it. If you have
any problems or suggestions please feel free to open up an issue or
submit a pull request. If the author of Advent of Code wishes for this
package to be taken down due to abuse or spam then I will be happy to
oblige.
There is a mandatory 5-second cooldown between sending the same request
twice in order to attempt to reduce the stress. Note that this classes
getQuestionHTML, getQuestionMarkdown and getQuestionPlaintext
into one cooldown as this is essentially the same request but is just
handled differently. If you wish to get two or all three at once, request getQuestionHTML
and then pass the output through
---
Within your browser, navigate to the Advent of Code site,
open dev tools and go to the tab labeled Network.
Load any Advent of Code page, click on the request for that page and look at
the Request header. It should contain a string that looks like sessions=
and then a bunch of characters. Everything after the = is your session token.
---
* Safari
* Firefox - Shortcut for Network tab
* Windows/Linux Control + Shift + E
* Max Command + Shift + E
* Firefox/Chrome - Shortcut for last tab
* Windows/Linux Control + Shift + I
* Max Command + Shift + I
---
Using npm
> npm install aoc-helper
Using yarn
> yarn add aoc-helper
---
In order to submit, get input or check Part 2 of questions, put your
session token line 20 of /example/index.js
Run example using npm
> npm run example
Run example using yarn
> yarn run example
Example code
``javascript
const {AoCHelper} = require('../lib');
const helper = new AoCHelper('Your token here');
helper.getQuestionPlaintext(1, 5)
.then(res => console.log(\n\nThis Year Day 5 Part 2 Question:\n${res}))
.catch(console.log);
helper.getInput()
.then(res => console.log(\n\nToday's Input: \n${res}))
.catch(console.log);
helper.submitAnswer(25245345, 2, 2, 2020)
.then(console.log)
.catch(console.log);
`
---
* AoCHelper
* submitAnswer
* getInput
* getQuestionHTML
* getQuestionMarkdown
* getQuestionPlaintext
* invalidateCache
* static htmlToMarkdown
* static htmlToPlaintext
---
All functions that take part, day or year can be omitted or null
passed as and they will default to the values below
* part - 1day
* - The current day 1 hour ahead of ESTyear
* - The current year if the current month is December, else last year
---
Arguments
* session - Your session token included in all Advent of Code requests
---
Arguments
* answer - Answer to questionpart
* - The specific part of the question, Should only be 1 or 2day
* - Day of the question to submityear
* - Year of the question to submitmaxIteration - Default:5
* - If this is set 1 or less it will not try to resubmit if you've been timed outfallbackCooldown - Default:10000
* - The cooldown to wait before resubmitting if you've been timed out, but the timeout could not be detected/parsed
Description
* Submits an answer for a specified day and part, if you've been submitting too quickly and get a cooldown it will detect how long it is and resubmit after the cooldown has finished. maxIterations and defaultCooldown are used as fallbacks where the cooldown cannot be detected/parsed.
---
Arguments
* day - Day of the input to getyear
* - Year of the input to get
Description
* Fetches the input of the specified day
---
Arguments
* part - Which part of the question to getday
* - Day of the questionyear
* - Year of the question
Description
* Fetches the question raw HTML
---
Arguments
* part - Which part of the question to getday
* - Day of the questionyear
* - Year of the question
Description
* Fetches the question HTML then uses Turndown to convert it to HTML which can be saved and viewed through an IDE or such
---
Arguments
* part - Which part of the question to getday
* - Day of the questionyear
* - Year of the question
Description
* Fetches the question HTML then strips all the HTML tabs so that which can be saved and viewed easier. If you use an IDE that supports viewing markdown, it's better to use getQuestionMarkdown as removing tags may occasionally break line breaks.
---
Description
* Invalidates the input cache, please never use this unless you absolutely need to.
---
Arguments
* html - HTML input to convert
Description
* Converts HTML to Markdown using Turndown
---
Arguments
* html` - HTML input to convert
Description
* Strips HTML tags from a given string