track qualified maps

This commit is contained in:
Michael Zhang 2020-10-14 20:00:26 -05:00
parent 5351a83762
commit f002e7c6fb
Signed by: michael
GPG key ID: BDA47A31A3C8EE6B

View file

@ -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)