-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprep.fish
executable file
·79 lines (61 loc) · 1.61 KB
/
prep.fish
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/usr/bin/env fish
#
# This is a fish script to pull the input file of the specific day.
#
# In order to execute, run:
#
# set -x AOC_SESSION "<session key>"
# . ./prep.fish <day>
#
# where "key" is the session key in your logged-in cookie, and "day" is
# the day you want to prep.
#
# Credit where it is due, the concept of this script was inspired heavily by 0xdf's version.
set AOC_DIR "/home/dan/Documents/aoc2022"
set AOC_URL_BASE "https://adventofcode.com/2022/day"
# AOC Session is not set
if test -z "$AOC_SESSION"
echo "AOC Session is not set!"
echo "Please enter 'set -x AOC_SESSION <session key>"
exit 1
end
if test -z "$argv[1]"
echo "Need the day we are working with, please enter the advent day"
echo "Example: ./prep.fish 5"
exit 2
end
set WORKDIR "$AOC_DIR/day$argv[1]"
mkdir -p $WORKDIR
cd $WORKDIR
set AOC_FULL "$AOC_URL_BASE/$argv[1]"
curl -s --cookie "session=$AOC_SESSION" "$AOC_FULL/input" > input
# Now let's set up the go stub
set GOFILE "day$argv[1].go"
echo > $WORKDIR/$GOFILE "\
package main
import (
\"os\"
\"bufio\"
\"fmt\"
\"flag\"
\"time\"
)
func main() {
t := time.Now()
filePtr := flag.String(\"f\", \"input\", \"Input file if not 'input'\")
flag.Parse()
readFile, err := os.Open(*filePtr)
if err != nil {
fmt.Println(\"Fatal:\", err)
}
defer readFile.Close()
fileScanner := bufio.NewScanner(readFile)
fileScanner.Split(bufio.ScanLines)
var lines []string
for fileScanner.Scan() {
lines = append(lines, fileScanner.Text())
}
// Insert code here
fmt.Printf(\"Total time elapsed: %s\\n\", time.Since(t))
}
"