getaoc/getaoc.go

37 lines
664 B
Go
Raw Normal View History

2019-12-01 03:58:20 +00:00
package getaoc
import (
"fmt"
"io/ioutil"
"log"
"net/http"
)
const base = "https://adventofcode.com"
func GetInput(session string, year, day int) string {
url := fmt.Sprintf("%s/%d/day/%d/input", base, year, day)
r, err := http.NewRequest(http.MethodGet, url, nil)
if err != nil {
panic(err)
}
r.AddCookie(&http.Cookie{
Name: "session",
Value: session,
Path: "",
Domain: ".adventofcode.com",
Secure: false,
HttpOnly: false,
SameSite: 0,
})
c := http.Client{}
resp, err := c.Do(r)
if err != nil {
log.Fatal(err)
}
defer resp.Body.Close()
body, _ := ioutil.ReadAll(resp.Body)
return string(body)
}