-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathget_input
More file actions
executable file
·33 lines (25 loc) · 1.08 KB
/
get_input
File metadata and controls
executable file
·33 lines (25 loc) · 1.08 KB
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
#!/bin/bash
export TZ="America/New_York"
[ "$(date +%m)" -eq 12 ] || exit
cd "$(dirname "$0")" || exit
. .env
if [[ ! -v SESSION ]]; then echo "Create .env with SESSION"; exit; fi;
# Usage:
# $ ./get_input [day]
# * day: day to fetch (default: today in EST)
# SESSION must be filled in below
# Run this manually once per day to fetch input
# Finding SESSION with Chrome (get value of adeventofcode.com session cookie)
# 1. Go to any https://adventofcode.com page while signed in
# 2. F12 -> Application -> Storage -> Cookies -> https://adventofcode.com
# 3. Copy value of 'session' cookie
# 4. Create .env in this directory containing: SESSION="session_Cookie_value_HERE"
#https://www.reddit.com/r/adventofcode/comments/z9dhtd/please_include_your_contact_info_in_the_useragent/
ua="https://github.com/Fragger/advent-of-code/blob/master/get_input by wonderfulweb@gmail.com"
year=$(date +%Y)
day=$((10#${1:-$(date +%d)}))
printf -v padDay %02d "$day"
if ! [ -f "$padDay" ]; then
curl "https://adventofcode.com/$year/day/$day/input" --cookie "session=$SESSION" -A "$ua" -o "$padDay"
fi
head "$padDay"