diff options
| author | LLLL Colonq <llll@colonq> | 2024-09-13 13:52:38 -0400 |
|---|---|---|
| committer | LLLL Colonq <llll@colonq> | 2024-09-13 13:52:38 -0400 |
| commit | d93ab7e848bf0f4bc1087504eecd7c959d19bf6c (patch) | |
| tree | f4f1806ceb56d2a68c9641313000f9a50fa77d78 /src/gizmo/wasp-aoc.el | |
| parent | cc3ccebbd3af825f5e4866532906f1a7a2756518 (diff) | |
Update :3
Diffstat (limited to 'src/gizmo/wasp-aoc.el')
| -rw-r--r-- | src/gizmo/wasp-aoc.el | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/src/gizmo/wasp-aoc.el b/src/gizmo/wasp-aoc.el new file mode 100644 index 00000000..5fa58582 --- /dev/null +++ b/src/gizmo/wasp-aoc.el @@ -0,0 +1,75 @@ +;;; wasp-aoc --- Advent of Code API access -*- lexical-binding: t; -*- +;;; Commentary: +;;; Code: + +(require 'dash) +(require 's) +(require 'f) +(require 'ht) +(require 'json) +(require 'request) +(require 'wasp-sensitive) + +(defcustom w/aoc-leaderboard-url "https://adventofcode.com/2023/leaderboard/private/view/3307583.json" + "URL for Advent of Code API." + :type '(string) + :group 'wasp) + +(defvar w/aoc-last-response nil) +(defvar w/aoc-user-stars nil) +(defconst w/aoc-name-map + '(("exodrifter_" . "exodrifter") + ("cephon_altera" . "lainlayer") + ("monochrome_0" . "monochrome") + ("yoink2000" . "darius1702") + ("lukeisun_" . "lukeisun") + ("dwinkley_" . "dwinkley") + ("lcolonq" . "llll colonq") + ("fn_lumi" . "lumi") + ("leadengin" . "leaden") + ("vasher_1025" . "vash3r") + ("andrewdtr" . "drawthatredstone"))) + +(defun w/aoc-max-stars () + "Return the maximum Advent of Code stars for today." + (* 2 (string-to-number (format-time-string "%d" (current-time))))) + +(defun w/aoc-lookup-stars (user) + "Retrieve the Advent of Code stars for USER." + (let* ((duser (s-downcase user)) + (cuser (s-downcase (alist-get duser w/aoc-name-map duser nil #'s-equals?)))) + (alist-get cuser w/aoc-user-stars nil nil #'s-equals?))) + +(defun w/aoc-fetch-api (k) + "Retrieve the current Advent of Code API. +Pass the resulting JSON to K." + (request + w/aoc-leaderboard-url + :type "GET" + :headers + `(("Cookie" . ,(format "session=%s" w/sensitive-aoc-session-cookie))) + :parser #'json-parse-buffer + :success + (cl-function + (lambda (&key data &allow-other-keys) + (setq w/aoc-last-response data) + (funcall k data)))) + nil) + +(defun w/aoc-update-user-stars () + "Update the Advent of Code stars list." + (w/aoc-fetch-api + (lambda (data) + (setf + w/aoc-user-stars + (--map + (cons (s-downcase (car it)) (cdr it)) + (--filter + (stringp (car it)) + (--map + (cons (ht-get it "name") (ht-get it "stars")) + (ht-values (ht-get data "members"))))))))) +;; (w/aoc-update-user-stars) + +(provide 'wasp-aoc) +;;; wasp-aoc.el ends here |
