(defpackage aoc (:use :cl) (:export #:split-lines #:test-input #:clear-data-cache)) (in-package :aoc) (defun load-ql-dependencies () ()) (defvar *aoc-url* "https://adventofcode.com") (defvar *cookie-jar* (cl-cookie:make-cookie-jar :cookies (list (cl-cookie:make-cookie :name "session" :value (uiop:getenv "AOC_SESSION") :origin-host "adventofcode.com" :path "/" :domain ".adventofcode.com" :secure-p t)))) (setf *cookie-jar* (cl-cookie:make-cookie-jar :cookies (list (cl-cookie:make-cookie :name "session" :value (uiop:getenv "AOC_SESSION") :origin-host "adventofcode.com" :path "/" :domain ".adventofcode.com" :secure-p t)))) (defun split-lines (s) (cl-ppcre:split "\\n" s)) (defun fetch-input-data (year day) (let ((url (format nil "~A/~D/day/~D/input" *aoc-url* year day))) (multiple-value-bind (body) (dex:get url :cookie-jar *cookie-jar* :verbose t) (split-lines body)))) (defvar *input-data-cache* (make-hash-table)) (defun clear-data-cache () (setf *input-data-cache* (make-hash-table))) (defun test-input (year day) "Return input data for the given challenge. Use a cached value if already fetched" (let* ((key (+ (* year 100) day)) (val (gethash key *input-data-cache*))) (if val val (setf (gethash key *input-data-cache*) (fetch-input-data year day)))))