63 lines
1.3 KiB
Go
Raw Normal View History

package main
import (
"fmt"
"os"
"time"
2019-04-23 05:52:55 +00:00
"github.com/akyoto/color"
2019-06-03 09:32:43 +00:00
"github.com/animenotifier/notify.moe/arn"
"github.com/animenotifier/twist"
)
var rateLimiter = time.NewTicker(500 * time.Millisecond)
func main() {
2018-03-28 22:26:19 +00:00
defer color.Green("Finished.")
2017-11-01 08:45:14 +00:00
defer arn.Node.Close()
// Replace this with ID list from twist.moe later
2017-07-11 11:12:10 +00:00
twistAnime, err := twist.GetAnimeIndex()
arn.PanicOnError(err)
2017-11-02 21:17:11 +00:00
idList := arn.IDList(twistAnime.KitsuIDs())
2018-04-04 19:05:07 +00:00
// Kitsu finder
finder := arn.NewAnimeFinder("kitsu/anime")
2017-07-12 00:57:53 +00:00
// Save index in cache
2017-11-02 21:17:11 +00:00
arn.DB.Set("IDList", "animetwist index", &idList)
2017-07-12 00:57:53 +00:00
2017-07-11 11:12:10 +00:00
color.Yellow("Refreshing twist.moe links for %d anime", len(idList))
2018-04-04 19:05:07 +00:00
for count, kitsuID := range idList {
anime := finder.GetAnime(kitsuID)
2018-04-04 19:05:07 +00:00
if anime == nil {
color.Red("Error fetching anime from the database with Kitsu ID %s", kitsuID)
2017-07-11 11:12:10 +00:00
continue
}
// Log
2017-07-11 11:12:10 +00:00
fmt.Fprintf(os.Stdout, "[%d / %d] ", count+1, len(idList))
2017-11-05 22:43:08 +00:00
if anime.Status != "current" {
fmt.Println("Not currently airing - skipping")
continue
}
2017-07-11 11:26:53 +00:00
// Refresh
2019-06-05 06:45:54 +00:00
err := anime.RefreshEpisodes()
if err != nil {
color.Red(err.Error())
continue
}
2017-07-11 11:26:53 +00:00
// Ok
2019-08-28 08:06:42 +00:00
color.Green("Found %d episodes for anime %s (Kitsu: %s)", len(anime.Episodes()), anime.ID, kitsuID)
2017-07-11 11:26:53 +00:00
// Wait for rate limiter
<-rateLimiter.C
}
}