npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

aoc-helper

v0.1.0

Published

Helper package to interact with the Advent of Code website programmatically through JavaScript

Downloads

2

Readme

Advent of Code Helper


DISCLAIMER - PLEASE READ

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

How to get session token


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.

How to open dev tools


  • 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

Installation


Using npm

npm install aoc-helper

Using yarn

yarn add aoc-helper

Example


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

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);

Documentation


AoCHelper


All functions that take part, day or year can be omitted or passed as null and they will default to the values below

  • part - 1
  • day - The current day 1 hour ahead of EST
  • year - The current year if the current month is December, else last year

new AoCHelper(session: string);


Arguments

  • session - Your session token included in all Advent of Code requests

submitAnswer(answer: string|number, part?: number, day?: number, year?: number, maxIterations?: number, fallbackCooldown?: number): Promise<string>


Arguments

  • answer - Answer to question
  • part - The specific part of the question, Should only be 1 or 2
  • day - Day of the question to submit
  • year - Year of the question to submit
  • maxIteration - Default:5 - If this is set 1 or less it will not try to resubmit if you've been timed out
  • fallbackCooldown - 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.

getInput(day?: number, year?: number): Promise<string>


Arguments

  • day - Day of the input to get
  • year - Year of the input to get

Description

  • Fetches the input of the specified day

getQuestionHTML(part?: number, day?: number, year?: number): Promise<string>


Arguments

  • part - Which part of the question to get
  • day - Day of the question
  • year - Year of the question

Description

  • Fetches the question raw HTML

getQuestionMarkdown(part?: number, day?: number, year?: number): Promise<string>


Arguments

  • part - Which part of the question to get
  • day - Day of the question
  • year - 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

getQuestionPlaintext(part?: number, day?: number, year?: number): Promise<string>


Arguments

  • part - Which part of the question to get
  • day - Day of the question
  • year - 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.

invalidateCache(): void


Description

  • Invalidates the input cache, please never use this unless you absolutely need to.

static htmlToMarkdown(html: string): string


Arguments

  • html - HTML input to convert

Description

  • Converts HTML to Markdown using Turndown

static htmlToPlaintext(html: string): string


Arguments

  • html - HTML input to convert

Description

  • Strips HTML tags from a given string