-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathaoc.el
31 lines (26 loc) · 915 Bytes
/
aoc.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
;;; -*- lexical-binding: t; -*-
(require 'request)
(defvar aoc-cookie
(with-temp-buffer
(insert-file-contents "~/code/aoc/cookie")
(buffer-string)))
(defun aoc-input-file (year day)
(format "~/code/aoc/input/%s/%s.in" year day))
(defun aoc-download-input (year day)
(let ((url (format "https://adventofcode.com/%d/day/%d/input"
year day)))
(request url
:type "GET"
;;; .... how to do this properly
:headers `(("Cookie" . ,(format "session=%S" aoc-cookie)))
:success (lambda (data)
data))))
(defmacro with-aoc-input (&rest body)
(declare (indent 0))
(let* ((path (split-string (buffer-file-name) "/"))
(year (string-to-number (nth 6 path)))
(day (string-to-number (substring (nth 7 path) 0 2))))
`(with-temp-buffer
(insert-file-contents (aoc-input-file ,(+ 2000 year) ,day))
,@body)))
(provide 'aoc-input-file)