From 0ebc0e2a7e2f92aa7f4b80a16aa41b73e72fe4eb Mon Sep 17 00:00:00 2001 From: David Ashby Date: Tue, 30 Nov 2021 20:10:44 -0500 Subject: [PATCH] automatically download inputs when making new folders --- .gitignore | 3 ++- 01/main.go | 44 -------------------------------------------- new.sh | 10 +++++++--- run.sh | 3 ++- 4 files changed, 11 insertions(+), 49 deletions(-) delete mode 100644 01/main.go diff --git a/.gitignore b/.gitignore index bb4b176..32e5f8c 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ -*/inputs \ No newline at end of file +*/inputs +.cookie \ No newline at end of file diff --git a/01/main.go b/01/main.go deleted file mode 100644 index 196f5ca..0000000 --- a/01/main.go +++ /dev/null @@ -1,44 +0,0 @@ -package main - -import ( - "bufio" - "fmt" - "os" - "time" -) - -func main() { - start := time.Now() - partOne() - duration := time.Since(start) - partTwo() - duration2 := time.Since(start) - fmt.Printf("p1: %s, p2: %s\n", duration, duration2-duration) -} - -func makeScanner(test bool) *bufio.Scanner { - var f *os.File - if test { - f, _ = os.Open("inputs/testinput") - } else { - f, _ = os.Open("inputs/input") - } - reader := bufio.NewReader(f) - return bufio.NewScanner(reader) -} - -func partOne() { - scanner := makeScanner(false) - - for scanner.Scan() { - // line := scanner.Text() - } -} - -func partTwo() { - scanner := makeScanner(false) - - for scanner.Scan() { - // line := scanner.Text() - } -} diff --git a/new.sh b/new.sh index 2776ede..d5556cc 100755 --- a/new.sh +++ b/new.sh @@ -1,7 +1,11 @@ #!/bin/bash +__year=2021 + if [ "${1}" != "" ]; then - mkdir -p ${1}/inputs - touch ${1}/inputs/{input,testinput} - cp -n main.go.tmpl ${1}/main.go + padded=$(printf "%02g" ${1}) + mkdir -p ${padded}/inputs + touch ${padded}/inputs/{input,testinput} + curl -s -H "Cookie: session=`cat .cookie`" https://adventofcode.com/${__year}/day/${1##0}/input > "${padded}/inputs/input" + cp -n main.go.tmpl ${padded}/main.go fi diff --git a/run.sh b/run.sh index e114129..2eeee27 100755 --- a/run.sh +++ b/run.sh @@ -1,7 +1,8 @@ #!/bin/bash if [ "${1}" != "" ]; then - cd ${1} + padded=$(printf "%02g" ${1}) + cd ${padded} go run *.go cd - > /dev/null fi