44 lines
900 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() {
// 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-07-11 11:12:10 +00:00
idList := twistAnime.KitsuIDs()
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
}
}