getaoc/cmd/getleaderboard/main.go

42 lines
709 B
Go

package main
import (
"flag"
"fmt"
"log"
"os"
"code.chrissexton.org/cws/getaoc"
)
var year = flag.Int("year", 2019, "event year")
var sessId = flag.String("session", "", "session id")
var boardId = flag.Int("id", 0, "board id")
const base = "https://adventofcode.com"
func main() {
flag.Parse()
if *boardId == 0 {
fmt.Fprintln(os.Stderr, "Error: Must provide a leaderboard id.")
return
}
sess, ok := os.LookupEnv("AOC_SESSION")
if !ok && *sessId == "" {
fmt.Fprintln(os.Stderr, "Error: Must provide a session id.")
return
}
if *sessId != "" {
sess = *sessId
}
body, err := getaoc.GetLeaderboard(sess, *year, *boardId)
if err != nil {
log.Fatal(err)
}
fmt.Println(body)
}