10 func GenInputFile(day int) string {
13 d = fmt.Sprintf("0%d", day)
15 d = fmt.Sprintf("%d", day)
19 path := fmt.Sprintf("%s/day%s/input.txt", pwd, d)
20 fi, _ := os.Stat(path)
25 fmt.Printf("Creating new input file %v...", path)
26 f, err := os.Create(path)
31 data := readHttp(2023, day)
32 _, err := f.WriteString(data)
40 func readHttp(year, day int) string {
41 fmt.Println("Fetching data into file...")
43 url := fmt.Sprintf("https://adventofcode.com/%d/day/%d/input", year, day)
44 session := os.Getenv("sessionAoC")
45 req, err := http.NewRequest("GET", url, nil)
50 req.AddCookie(&http.Cookie{Name: "session", Value: session})
51 client := &http.Client{}
52 resp, err := client.Do(req)
57 body, err := io.ReadAll(resp.Body)