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 (
|
2020-10-12 12:23:32 +00:00
|
|
|
refreshInterval = 30 * time.Second
|
2020-10-15 14:35:31 +00:00
|
|
|
lastUpdateTime time.Time
|
2020-10-12 13:47:28 +00:00
|
|
|
Ticker = time.NewTicker(refreshInterval)
|
2020-10-11 19:32:58 +00:00
|
|
|
)
|
|
|
|
|
2020-10-15 14:35:31 +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
|
|
|
}
|
|
|
|
|
2020-10-15 14:35:31 +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
|
|
|
|
2020-10-15 14:35:31 +00:00
|
|
|
scraper := Scraper{config, bot, db, api}
|
2020-10-11 19:32:58 +00:00
|
|
|
|
2020-10-15 14:35:31 +00:00
|
|
|
go func() {
|
|
|
|
for ; true; <-Ticker.C {
|
|
|
|
scraper.scrapePendingMaps()
|
2020-10-12 04:22:47 +00:00
|
|
|
|
2020-10-15 14:35:31 +00:00
|
|
|
scraper.scrapeNominatedMaps()
|
2020-10-11 19:32:58 +00:00
|
|
|
}
|
2020-10-15 14:35:31 +00:00
|
|
|
}()
|
2020-10-11 19:32:58 +00:00
|
|
|
}
|