-
Notifications
You must be signed in to change notification settings - Fork 3
/
Makefile
48 lines (35 loc) · 1.28 KB
/
Makefile
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
JQ := $(wildcard ????/*.jq)
TASK := $(JQ:.jq=)
.PHONY: all
all: $(TASK)
.PHONY: $(TASK)
.SECONDEXPANSION:
$(TASK) : % : $$(subst -1,,$$(subst -2,,$$(subst +,,$$@))).input %.jq
jq --raw-input --null-input --from-file $@.jq $<
ADVENT_OF_CODE_SESSION ?= $(shell security find-generic-password -s adventofcode.com -a me -w)
%.input:
curl --fail --output $@ --cookie session="${ADVENT_OF_CODE_SESSION}" \
"https://adventofcode.com/$(dir $@)day/$(patsubst 0%,%,$(notdir $*))/input"
%.sample:
curl "https://adventofcode.com/$(dir $@)day/$(patsubst 0%,%,$(notdir $*))" \
| xmllint --html --xpath "/html/body/main/article/pre[1]/code/text()" - 2>/dev/null \
| sed '$${/^$$/d;}' >$@
.PHONY: save-session
save-session:
security add-generic-password -U -s adventofcode.com -a me -w
POST := $(addsuffix .post,$(JQ))
.PHONY: $(POST)
$(POST):
@echo "[LANGUAGE: jq] [github](https://github.com/odnoletkov/advent-of-code-jq)"
@echo
@sed "s/^/ /" $(@:.post=)
last-post:
@make $$(ls ????/??-?.jq | sort | tail -n 1).post
today-url:
@date +"https://adventofcode.com/%Y/day/%-d"
today-text:
@curl --silent --fail "$$(make today-url)" | pandoc -f html -t plain
stats:
@find . -name \*.jq | cut -c 3-6 | sort | uniq -c
record:
@asciinema rec -c 'vim $$(date +%Y/%d.input)' $$(date +%Y/%d.asciinema)