Files
advent-of-code-go/scripts/aoc/input.go
T
2021-12-01 22:13:12 -05:00

30 lines
689 B
Go

package aoc
import (
"fmt"
"path/filepath"
"strings"
"github.com/alexchao26/advent-of-code-go/util"
)
func GetInput(day, year int, cookie string) {
fmt.Printf("fetching for day %d, year %d\n", day, year)
// make the request
url := fmt.Sprintf("https://adventofcode.com/%d/day/%d/input", year, day)
body := GetWithAOCCookie(url, cookie)
if strings.HasPrefix(string(body), "Puzzle inputs differ by user") {
panic("'Puzzle inputs differ by user' response")
}
// write to file
filename := filepath.Join(util.Dirname(), "../..", fmt.Sprintf("%d/day%02d/input.txt", year, day))
WriteToFile(filename, body)
fmt.Println("Wrote to file: ", filename)
fmt.Println("Done!")
}