37 lines
664 B
Go
37 lines
664 B
Go
|
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)
|
||
|
}
|