| Copyright | (c) Justin Le 2018 |
|---|---|
| License | BSD3 |
| Maintainer | justin@jle.im |
| Stability | experimental |
| Portability | non-portable |
| Safe Haskell | None |
| Language | Haskell2010 |
Advent
Description
Haskell bindings for Advent of Code 2018 API. Caches and throttles requests automatically.
Specify your requests with AoC and AoCOpts, and run them with
runAoC.
Examples:
-- Fetch prompts for day 5runAoCmyOpts $AoCPrompt(mkDay_5) -- Fetch input for day 8runAoCmyOpts $AoCInput(mkDay_8) -- Submit answer "hello" for Day 10, Part 1runAoCmyOpts $AoCSubmit(mkDay_10)Part1"hello"
Please use responsibly. All actions are by default rate limited to one per three seconds, but this can be adjusted to a hard-limited cap of one per second.
Note that leaderboard API is not yet supported.
Synopsis
- data AoC :: Type -> Type where
- data Part
- data AoCOpts = AoCOpts {
- _aSessionKey :: String
- _aYear :: Integer
- _aCache :: Maybe FilePath
- _aForce :: Bool
- _aThrottle :: Int
- _aCurlOpts :: [CurlOption]
- data SubmitRes
- = SubCorrect (Maybe Integer)
- | SubIncorrect Int (Maybe String)
- | SubWait Int
- | SubInvalid
- | SubUnknown String
- showSubmitRes :: SubmitRes -> String
- runAoC :: AoCOpts -> AoC a -> IO (Either AoCError a)
- defaultAoCOpts :: Integer -> String -> AoCOpts
- data AoCError
- challengeReleaseTime :: Integer -> Finite 25 -> UTCTime
- timeToRelease :: Integer -> Finite 25 -> IO NominalDiffTime
- challengeReleased :: Integer -> Finite 25 -> IO Bool
- mkDay :: Integer -> Maybe (Finite 25)
- mkDay_ :: Integer -> Finite 25
- dayInt :: Finite 25 -> Integer
- aocDay :: AoC a -> Finite 25
- partChar :: Part -> Char
- partInt :: Part -> Int
- setAoCThrottleLimit :: Int -> IO ()
- getAoCThrottleLimit :: IO Int
- parseSubmitRes :: Text -> SubmitRes
- processHTML :: String -> [Text]
API
data AoC :: Type -> Type where Source #
An API command. An an AoC API request that returns
results of type AoC aa.
A lot of these commands take , which represents a day of
December up to and including Christmas Day (December 25th). You can
convert an integer day (1 - 25) into a Finite 25 representing that
day using Finite 25mkDay or mkDay_.
Constructors
| AoCPrompt :: Finite 25 -> AoC (Map Part Text) | Fetch prompts for a given day. Returns a |
| AoCInput :: Finite 25 -> AoC Text | Fetch input, as plaintext. Returned verbatim. Be aware that input might contain trailing newlines. |
| AoCSubmit :: Finite 25 -> Part -> String -> AoC (Text, SubmitRes) | Submit a plaintext answer (the WARNING: Answers are not length-limited. Answers are stripped
of leading and trailing whitespace and run through |
A given part of a problem. All Advent of Code challenges are two-parts.
You can usually get Part1 (if it is already released) with a nonsense
session key, but Part2 always requires a valid session key.
Note also that Challenge #25 typically only has a single part.
Setings for running an API request.
Session keys are required for all commands, but if you enter a bogus key
you should be able to get at least Part 1 from AoCPrompt.
The session key can be found by logging in on a web client and checking the cookies. You can usually check these with in-browser developer tools.
Throttling is hard-limited to a minimum of 1 second between calls. Please be respectful and do not try to bypass this.
Constructors
| AoCOpts | |
Fields
| |
Instances
| Show AoCOpts Source # | |
| Generic AoCOpts Source # | |
| type Rep AoCOpts Source # | |
Defined in Advent type Rep AoCOpts = D1 (MetaData "AoCOpts" "Advent" "advent-of-code-api-0.1.2.2-8fQNfOkNful7Ccka34GDuu" False) (C1 (MetaCons "AoCOpts" PrefixI True) ((S1 (MetaSel (Just "_aSessionKey") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 String) :*: (S1 (MetaSel (Just "_aYear") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 Integer) :*: S1 (MetaSel (Just "_aCache") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 (Maybe FilePath)))) :*: (S1 (MetaSel (Just "_aForce") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 Bool) :*: (S1 (MetaSel (Just "_aThrottle") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 Int) :*: S1 (MetaSel (Just "_aCurlOpts") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 [CurlOption]))))) | |
The result of a submission.
Constructors
| SubCorrect (Maybe Integer) | Correct submission, including global rank (if reported, which usually happens if rank is under 1000) |
| SubIncorrect Int (Maybe String) | Incorrect submission. Contains the number of seconds you must
wait before trying again. The |
| SubWait Int | Submission was rejected because an incorrect submission was recently submitted. Contains the number of seconds you must wait before trying again. |
| SubInvalid | Submission was rejected because it was sent to an invalid question or part. Usually happens if you submit to a part you have already answered or have not yet unlocked. |
| SubUnknown String | Could not parse server response. Contains parse error. |
Instances
defaultAoCOpts :: Integer -> String -> AoCOpts Source #
Sensible defaults for AoCOpts for a given year and session key.
Use system temporary directory as cache, and throttle requests to one request per three seconds.
A possible (syncronous, logical, pure) error returnable from runAoC.
Does not cover any asynchronous or IO errors.
Constructors
| AoCCurlError CurlCode String | A libcurl error, with response code and response body |
| AoCReleaseError NominalDiffTime | Tried to interact with a challenge that has not yet been released. Contains the amount of time until release. |
| AoCThrottleError | The throttler limit is full. Either make less requests, or adjust
it with |
Instances
| Show AoCError Source # | |
| Generic AoCError Source # | |
| Exception AoCError Source # | |
Defined in Advent Methods toException :: AoCError -> SomeException # fromException :: SomeException -> Maybe AoCError # displayException :: AoCError -> String # | |
| type Rep AoCError Source # | |
Defined in Advent type Rep AoCError = D1 (MetaData "AoCError" "Advent" "advent-of-code-api-0.1.2.2-8fQNfOkNful7Ccka34GDuu" False) (C1 (MetaCons "AoCCurlError" PrefixI False) (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 CurlCode) :*: S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 String)) :+: (C1 (MetaCons "AoCReleaseError" PrefixI False) (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 NominalDiffTime)) :+: C1 (MetaCons "AoCThrottleError" PrefixI False) (U1 :: Type -> Type))) | |
Calendar
Arguments
| :: Integer | year |
| -> Finite 25 | day |
| -> IO NominalDiffTime |
Get time until release of a given challenge.
Check if a challenge has been released yet.
Utility
Day
Part
Throttler
setAoCThrottleLimit :: Int -> IO () Source #
Set the internal throttler maximum queue capacity. Default is 100.
getAoCThrottleLimit :: IO Int Source #
Get the internal throttler maximum queue capacity.