From f002e7c6fba0a3736cf9cb667ad0060efd1976df Mon Sep 17 00:00:00 2001 From: Michael Zhang Date: Wed, 14 Oct 2020 20:00:26 -0500 Subject: [PATCH] track qualified maps --- scrape/scrape.go | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/scrape/scrape.go b/scrape/scrape.go index a1cbafe..eab2671 100644 --- a/scrape/scrape.go +++ b/scrape/scrape.go @@ -34,6 +34,8 @@ func RunScraper(config *config.Config, bot *discord.Bot, db *db.Db, api *osuapi. } allNewMaps := make(map[int][]osuapi.Beatmapset, 0) + + // add pending maps var newLastUpdateTime = time.Unix(0, 0) for _, beatmapSet := range pendingSets.Beatmapsets { updatedTime, err := time.Parse(time.RFC3339, beatmapSet.LastUpdated) @@ -60,6 +62,35 @@ func RunScraper(config *config.Config, bot *discord.Bot, db *db.Db, api *osuapi. } } + // add qualified maps + qualifiedSets, err := api.SearchBeatmaps("qualified") + if err != nil { + log.Println("error fetching pending sets", err) + } + + for _, beatmapSet := range qualifiedSets.Beatmapsets { + updatedTime, err := time.Parse(time.RFC3339, beatmapSet.LastUpdated) + if err != nil { + log.Println("error parsing last updated time", updatedTime) + } + + if updatedTime.After(newLastUpdateTime) { + // update lastUpdateTime to latest updated map + newLastUpdateTime = updatedTime + } + + if !updatedTime.After(lastUpdateTime) { + break + } + + mapperId := beatmapSet.UserID + if _, ok2 := allNewMaps[mapperId]; !ok2 { + allNewMaps[mapperId] = make([]osuapi.Beatmapset, 0) + } + + allNewMaps[mapperId] = append(allNewMaps[mapperId], beatmapSet) + } + if len(allNewMaps) > 0 { for mapperId, newMaps := range allNewMaps { channels := make([]string, 0)