subscribe-bot/scrape/scrape.go

38 lines
639 B
Go
Raw Normal View History

2020-10-12 13:47:28 +00:00
package scrape
2020-10-11 19:32:58 +00:00
import (
"time"
2020-10-12 13:47:28 +00:00
2020-10-12 14:25:50 +00:00
"subscribe-bot/config"
2020-10-12 13:47:28 +00:00
"subscribe-bot/db"
"subscribe-bot/discord"
"subscribe-bot/osuapi"
2020-10-11 19:32:58 +00:00
)
var (
refreshInterval = 30 * time.Second
lastUpdateTime time.Time
2020-10-12 13:47:28 +00:00
Ticker = time.NewTicker(refreshInterval)
2020-10-11 19:32:58 +00:00
)
type Scraper struct {
config *config.Config
bot *discord.Bot
db *db.Db
api *osuapi.Osuapi
2020-10-11 19:32:58 +00:00
}
func RunScraper(config *config.Config, bot *discord.Bot, db *db.Db, api *osuapi.Osuapi) {
lastUpdateTime = time.Now()
2020-10-11 19:32:58 +00:00
scraper := Scraper{config, bot, db, api}
2020-10-11 19:32:58 +00:00
go func() {
for ; true; <-Ticker.C {
scraper.scrapePendingMaps()
2020-10-12 04:22:47 +00:00
scraper.scrapeNominatedMaps()
2020-10-11 19:32:58 +00:00
}
}()
2020-10-11 19:32:58 +00:00
}