last_star_ts is now an number!

This commit is contained in:
Brian Buller 2020-12-18 12:45:04 -06:00
parent a3d9eb97a9
commit 495a1b6371

16
aoc.go
View File

@ -6,8 +6,6 @@ import (
"fmt" "fmt"
"io/ioutil" "io/ioutil"
"net/http" "net/http"
"strconv"
"strings"
"time" "time"
) )
@ -84,17 +82,17 @@ func (a *AoC) fetchLeaderboard(year int) (*Leaderboard, error) {
return nil, err return nil, err
} }
strBody := string(body) strBody := string(body)
strBody = strings.ReplaceAll(strBody, "\"last_star_ts\":0", "\"last_star_ts\":\"0\"") //strBody = strings.ReplaceAll(strBody, "\"last_star_ts\":0", "\"last_star_ts\":\"0\"")
err = json.Unmarshal([]byte(strBody), &leaderboard) err = json.Unmarshal([]byte(strBody), &leaderboard)
if err != nil { if err != nil {
return nil, err return nil, err
} }
for k, mbr := range leaderboard.Members { for k, mbr := range leaderboard.Members {
starTs, err := strconv.ParseInt(mbr.RawStarTs, 10, 64) //starTs, err := strconv.ParseInt(mbr.RawStarTs, 10, 64)
if err != nil { //if err != nil {
continue // continue
} //}
mbr.LastStarTs = time.Unix(starTs, 0) mbr.LastStarTs = time.Unix(mbr.RawStarTs, 0)
leaderboard.Members[k] = mbr leaderboard.Members[k] = mbr
} }
leaderboard.LastFetch = time.Now() leaderboard.LastFetch = time.Now()
@ -113,7 +111,7 @@ type Member struct {
ID string `json:"id"` ID string `json:"id"`
Name string `json:"name"` Name string `json:"name"`
Stars int `json:"stars"` Stars int `json:"stars"`
RawStarTs string `json:"last_star_ts"` RawStarTs int64 `json:"last_star_ts"`
LocalScore int `json:"local_score"` LocalScore int `json:"local_score"`
GlobalScore int `json:"global_score"` GlobalScore int `json:"global_score"`
LastStarTs time.Time LastStarTs time.Time