-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.nu
executable file
·64 lines (56 loc) · 2.45 KB
/
init.nu
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/usr/bin/env nu
# can be empty, must be string
def main [day?: string, year?: string] = {
# if empty get current day / year
let day = match $day {
null => { date now | format date %d }
_ => $day
}
let day = $day | into int
let year = match $year {
null => { date now | format date %Y }
_ => $year
}
if $day not-in 1..25 {
print "fuck you - day not in range"
exit
}
# add leading 0 for better folder structure
let day_for_folder = if ($day | into int) < 10 { ['0', $day] | str join } else { $day }
# user agent for no abuse and session for auth
$env.AOC_USER_AGENT = "[email protected]"
$env.AOC_SESSION = (open ./AoC_private/session.txt)
mkdir $"./($year)/($day_for_folder)"
mkdir $"./AoC_private/($year)/($day_for_folder)"
# aocd module (pip install advent-of-code-data) to get and cache inputs etc.
aocd $day $year | str trim -r | save $"./AoC_private/($year)/($day_for_folder)/input.txt" -f
aocd $day $year --example | str trim -r | save $"./($year)/($day_for_folder)/example.txt" -f
let headers = {
cookie: $"session=($env.AOC_SESSION)"
headers: $"User-Agent=($env.AOC_USER_AGENT)"
}
# get aoc html site, get start and end of text and paste it to statement file
# will include solutions if logged in and already submitted
let site = http get $"https://adventofcode.com/($year)/day/($day)" --headers $headers
let start = $site | str index-of "<article"
let end = ($site | str index-of -e "</article>") + ('</article>' | str length )
let end_success = ($site | str index-of -e "</code>") + ('</code>' | str length )
let eend = if $end_success != null { [$end | $end_success] | math max } else { $end }
$site | str substring $start..$eend | str trim -r | save $"./AoC_private/($year)/($day_for_folder)/statement.html" -f
cd ./AoC_private
try {
^git add .
^git commit -m $"($year)/($day_for_folder)"
}
cd ..
# create link url
$"[InternetShortcut]\nURL=https://adventofcode.com/($year)/day/($day)\n" | save $"./($year)/($day_for_folder)/link.url" -f
# create code template
^python make_code.py $day $year
# open template
^code $"./($year)/($day_for_folder)/code.py" $"./AoC_private/($year)/($day_for_folder)/input.txt"
# paste output to cosnole
^aocd
# open browser with todays site
^$env.BROWSER $"https://adventofcode.com/($year)/day/($day)"
}