GithubHelp home page GithubHelp logo

apexatoll / aoc-cli Goto Github PK

View Code? Open in Web Editor NEW
56.0 4.0 2.0 83.44 MB

Command line interface for Advent of Code, built in Ruby using Kangaru

License: MIT License

Ruby 97.25% Shell 0.09% HTML 2.66%
advent-of-code aoc cli ruby kangaru

aoc-cli's Introduction

aoc-cli

Gem Version aoc-ci codecov

A command-line interface for Advent of Code, built in Ruby.

Important

aoc_cli has gone through a complete rewrite as of 1.0.0 in order to improve resilience and the overall user interface. The core application has been swapped out to use the Kangaru command line framework, with a completely new API and removal of bloated features. There are also some other improvements on performance, and removal of some hefty dependencies such as pandoc. These are breaking changes, so please pin your version to 0.2.3 if you wish to continue using the previous version.

Main Features

  • Download puzzles as markdown and raw inputs directly from the command line
  • Submit answers for puzzles and receive feedback
  • Track data on your progress through the event

Installation

  • As of 1.0.0, aoc_cli no longer requires pandoc
  • Other system requirements are curl and sqlite3 and ruby >= 3.2.0

Install aoc_cli with the following command

gem install aoc_cli

Setup

Setting your Session Key

To use aoc-cli you must first find and store your unique session cookie. To find this, log into the Advent of Code website as usual and load any page.

Open developer tools and open the network tab. Refresh the page and you should see a file that contains your session cookie.

It will contain a field that looks something like:

cookie: session=HEXADECIMAL_STRING

This is unique to your account, and allows aoc-cli to interact with the AoC server on your behalf - do not share this or check this into version control.

Your session token should be copied into your configuration file (~/.config/aoc_cli/config.yml) under the session.token nested key:

session:
  token: <YOUR TOKEN>

Important

Make sure to strip the session= prefix from the copied token.

Note

Multiple users used to be a feature pre the 1.0.0 overhaul. This will be reimplemented and released in an upcoming release if there is need for it.

Usage

aoc-cli is designed to run in a file-tree generated by the application.

There are two types of directories

  1. Event directories
  • These contain puzzle subdirectories
  1. Puzzle subdirectories
  • These contain puzzles, input and your soution code

Directory Structure Example

  2023 <--- Event Directory
  │     
  ├── 1 <-- Puzzle Directory
  │   │ 
  │   ├── day_1.md
  │   ├── input
  │   └── solution.rb
  └── 2
      ├── day_2.md
      ├── input
      └── solution.rs

Initialising an Event

To begin using the cli you must first initialise an event directory. An event directory is the parent directory in which your puzzle directories (and your code solutions) exist.

Note

If you are planning on tackling multiple Advent of Code events, it is probably wise to create a root for your event directories, eg ~/aoc.

To initialize an event, run the following command:

aoc event init <YEAR>

This will:

  • Fetch your latest stats and setup your progress
  • Create an event directory

At the time of writing, the valid years are 2015 - 2023.

Initialising a Puzzle

Caution

Please do not check puzzle or input files into your version control system, as this is against Advent of Code rules.

Run the following command from an event directory to fetch and initialize a puzzle directory and associated files:

aoc puzzle init <DAY>

This command performs the following actions

  • Creates a puzzle subdirectory
  • Fetches the puzzle as markdown and writes to the puzzle dir
  • Fetches raw puzzle input and writes to the puzzle dir

This directory is a good place to write your solution code adjacent to your input and puzzle files.

Solving Puzzles

From the puzzle subdirectory you can solve puzzles by running the command

aoc puzzle solve --answer <ANSWER>

You will then receive one of three responses

  1. The answer was correct
  2. The answer was not correct
  3. You have time to wait before submitting an answer

If your answer is correct, aoc-cli will automatically update the puzzle instructions and your event progress.

Incorrect attempts will be logged along with any hint as to whether your answer was too high or too low. You can recall these using the puzzle attempts command.

If you have sent multiple incorrect attempts AoC will ask you to wait before trying to answer the puzzle again.

Tables

aoc-cli uses a local SQLite database to store information about your progress with puzzles. This tracks data on:

  1. Your progress for the current event
  2. Your attempts for the current puzzle

This data can be visualised in terminal-friendly tables

Attempts

Previous attempts for a puzzle can be viewed from the puzzle directory by the use of the command:

aoc puzzle attempts

Progress

To view your progress in the year you can run the following command from within an event or a puzzle directory.

aoc event progress

This will print a simple table showing your stars for each day. This is created on year initialisation and updated as you complete puzzles

Help

aoc-cli also has built in documentation. You can view this from the terminal using either aoc help <COMMAND> or aoc <COMMAND> --help.

Contributing

Please create an issue if there are any bugs or problems using aoc-cli. Contributions and questions are always welcome.

Acknowledgments

aoc-cli is in no way affiliated with Advent of Code, but I would like to take this opportunity to thank the creator, Eric Wastl, for his efforts in producing these fantastic puzzles year on year.

aoc-cli's People

Contributors

apexatoll avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

yspreen gmoraleda

aoc-cli's Issues

It's 2021!

edit: since this project is abandoned and in ruby, I decided to rewrite it in python. exact same functionality, see here: https://github.com/yspreen/aoc


> aoc -y 2021             
Error: Invalid year: 2021
Advent of Code currently spans 2015 - 2020.

Help wanted to migrate from old version of the tool.

I enjoy that this project got some TLC recently. But currently trying to use it with events and puzzles already set up from the previous version means I need to manually edit a sqlite database to get all the locations and attempts and such set correctly. Is there a tool or such in the works to help with this task?

Support for 2021

2021 is currently not supported:

$ aoc -y 2021
Error: Invalid year: 2021
Advent of Code currently spans 2015 - 2020.

Cannot submit the second part of the solution

edit: since this project is abandoned and in ruby, I decided to rewrite it in python. exact same functionality, see here: https://github.com/yspreen/aoc


-s works once, but if I do it for part 2:

✗ aoc -s 8295
/Library/Ruby/Gems/2.6.0/gems/aoc_cli-0.2.3/lib/aoc_cli/solve.rb:33:in `const_get': no implicit conversion of nil into String (TypeError)
        from /Library/Ruby/Gems/2.6.0/gems/aoc_cli-0.2.3/lib/aoc_cli/solve.rb:33:in `respond'
        from /Library/Ruby/Gems/2.6.0/gems/aoc_cli-0.2.3/lib/aoc_cli/commands.rb:74:in `exec'
        from /Library/Ruby/Gems/2.6.0/gems/aoc_cli-0.2.3/lib/aoc_cli/interface.rb:10:in `run'
        from /Library/Ruby/Gems/2.6.0/gems/aoc_cli-0.2.3/lib/aoc_cli/interface.rb:6:in `initialize'
        from /Library/Ruby/Gems/2.6.0/gems/aoc_cli-0.2.3/bin/aoc:4:in `new'
        from /Library/Ruby/Gems/2.6.0/gems/aoc_cli-0.2.3/bin/aoc:4:in `<top (required)>'
        from /usr/local/bin/aoc:23:in `load'
        from /usr/local/bin/aoc:23:in `<main>'

Better handling of the session= error

I had the same issue as #1

The problem is, once you set the session wrong, doing it with the right format results in

> aoc -k 'session=53616c...'
wrong number of arguments (given 0, expected 1)

I think the aoc -k command should check for the right format. The error message showcased in #1 should also be more informative

Prevent resubmission

Just a really small improvement. I accidentally hit the same command twice, meaning I submitted the same (wrong) answer twice. So I had to wait 1min before submitting the correct one. You could check if an answer was submitted before and catch it

Error when downloading part two

Correct! Downloading part two...
no implicit conversion of nil into String

I think I had this before, and downgraded to a pretty old version. Today I reinstalled everything, deleted all DBs and caches, and the issue is back.

Error while trying to show the answer of part 1: undefined method border=

This is the error I get:

➜  22 git:(main) ✗ aoc -p 1 -a
undefined method `border=' for #<Terminal::Table::Style:0x00007fa517970d10>
Did you mean?  border_x=
               border_i=
               border_y=
               border_i
               border_x
               border_y

In the example, I tried to retrieve my answer for part 1 after solving it.

I use zsh, ohmyzsh and hyper.is

Puzzle inputs differ by user. Please log in to get your puzzle input.

I keep getting that text in my input files. I already tried with a fresh folder, setting the key again, nothing. Even deleted my local db in the .config folder.

I think my session ran out a while ago, so it makes sense that I have to set a new one. But something seems to have changed. The method of going to the website and copying the session id from the browser cookies doesn't successfully authenticate the tool anymore

Broken for text solutions?

(.pyenv) ➜  07 git:(main) ✗ aoc -s vgzejbd
no such column: vgzejbd
(.pyenv) ➜  07 git:(main) ✗ aoc -s "vgzejbd"
no such column: vgzejbd

This is for 2017 day 7.

Error when initializing year

Hi.

When I run aoc -y 2020 to initialize the year, I get this error:

no implicit conversion from nil to integer

I'm on Mac, with Ruby from Homebrew (ruby 3.0.0p0 (2020-12-25 revision 95aff21468) [x86_64-darwin20])
I've tried running the command in both zsh and bash. Have tried both gem and manual install.
The session token is stored in ~/.config/aoc-cli

Initializing a year tells me "no such file or directory - pandoc"

[10:14:06] % bundle exec aoc -y 2020
No such file or directory - pandoc

Meta file was created as such:

[10:14:31] % less .meta
dir=>ROOT
user=>agargiulo
year=>2020

Running ruby 2.7.2 on macOS Big Sur 11.2.1
To install, I added gem 'aoc_cli' to my Gemfile and ran bundle install

implicit conversion from nil

edit: since this project is abandoned and in ruby, I decided to rewrite it in python. exact same functionality, see here: https://github.com/yspreen/aoc


This is happening for part two in 2016, day 18.
I could fix the issue (day.md was not updating) by running -r:

 aoc -s 19991126
Correct! This day is now complete!
- Updating calendar...
no implicit conversion from nil to integer
(.pyenv) ➜  18 git:(main) ✗ aoc -r
- Updating puzzle...

Installation according to README fails.

This is my process:

➜  ~ brew install pandoc
Updating Homebrew...
==> Auto-updated Homebrew!
######################################################################## 100.0%
==> Pouring pandoc-2.11.4.catalina.bottle.tar.gz
🍺  /usr/local/Cellar/pandoc/2.11.4: 10 files, 146.0MB
➜  ~ sudo gem install aoc_cli
Password:
Fetching aoc_cli-0.1.3.gem
Fetching colorize-0.8.1.gem
Fetching pandoc-ruby-2.1.4.gem
Fetching curb-0.9.11.gem
Successfully installed colorize-0.8.1
Building native extensions. This could take a while...
ERROR:  Error installing aoc_cli:
        ERROR: Failed to build gem native extension.

    current directory: /Library/Ruby/Gems/2.6.0/gems/curb-0.9.11/ext
/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/bin/ruby -I /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0 -r ./siteconf20210219-55535-vekesv.rb extconf.rb
checking for curl-config... yes
checking for curlopt_tcp_keepalive... *** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers.  Check the mkmf.log file for more details.  You may
need configuration options.

Provided configuration options:
        --with-opt-dir
        --without-opt-dir
        --with-opt-include
        --without-opt-include=${opt-dir}/include
        --with-opt-lib
        --without-opt-lib=${opt-dir}/lib
        --with-make-prog
        --without-make-prog
        --srcdir=.
        --curdir
        --ruby=/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/bin/$(RUBY_BASE_NAME)
        --with-curl-dir
        --without-curl-dir
        --with-curl-include
        --without-curl-include=${curl-dir}/include
        --with-curl-lib
        --without-curl-lib=${curl-dir}/lib
/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:467:in `try_do': The compiler failed to generate an executable file. (RuntimeError)
You have to install development tools first.
        from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:585:in `block in try_compile'
        from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:534:in `with_werror'
        from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:585:in `try_compile'
        from extconf.rb:52:in `block in have_constant'
        from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:959:in `block in checking_for'
        from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:361:in `block (2 levels) in postpone'
        from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:331:in `open'
        from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:361:in `block in postpone'
        from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:331:in `open'
        from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:357:in `postpone'
        from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:958:in `checking_for'
        from extconf.rb:44:in `have_constant'
        from extconf.rb:62:in `<main>'

To see why this extension failed to compile, please check the mkmf.log which can be found here:

  /Library/Ruby/Gems/2.6.0/extensions/universal-darwin-19/2.6.0/curb-0.9.11/mkmf.log

extconf failed, exit code 1

Gem files will remain installed in /Library/Ruby/Gems/2.6.0/gems/curb-0.9.11 for inspection.
Results logged to /Library/Ruby/Gems/2.6.0/extensions/universal-darwin-19/2.6.0/curb-0.9.11/gem_make.out
➜  ~ 

Custom Naming for Day Directory

Would it be possible to set a custom naming format for the day directory that is created with the aoc -d command. This would be useful in Java projects where sub-directories (that are treated as packages) can't start with a number (usually just prefixed with an underscore).

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.