49 lines
1013 B
Go
Raw Normal View History

package main
import (
"fmt"
"os"
"time"
"github.com/animenotifier/arn"
"github.com/animenotifier/twist"
"github.com/fatih/color"
)
var rateLimiter = time.NewTicker(500 * time.Millisecond)
func main() {
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())
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))
2017-07-11 11:12:10 +00:00
for count, animeID := range idList {
anime, animeErr := arn.GetAnime(animeID)
2017-07-11 11:12:10 +00:00
if animeErr != nil {
color.Red("Error fetching anime from the database with ID %s: %v", animeID, animeErr)
continue
}
// Log
2017-07-11 11:12:10 +00:00
fmt.Fprintf(os.Stdout, "[%d / %d] ", count+1, len(idList))
2017-07-11 11:26:53 +00:00
// Refresh
anime.RefreshEpisodes()
2017-07-11 11:26:53 +00:00
// Ok
color.Green("Found %d episodes for anime %s", len(anime.Episodes().Items), animeID)
2017-07-11 11:26:53 +00:00
// Wait for rate limiter
<-rateLimiter.C
}
}