2017-07-09 21:22:31 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2017-07-10 14:58:34 +00:00
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
"time"
|
2017-07-09 21:22:31 +00:00
|
|
|
|
|
|
|
"github.com/animenotifier/arn"
|
|
|
|
"github.com/animenotifier/twist"
|
|
|
|
"github.com/fatih/color"
|
|
|
|
)
|
|
|
|
|
2017-07-10 14:58:34 +00:00
|
|
|
var rateLimiter = time.NewTicker(500 * time.Millisecond)
|
|
|
|
|
2017-07-09 21:22:31 +00:00
|
|
|
func main() {
|
2017-11-01 08:45:14 +00:00
|
|
|
defer arn.Node.Close()
|
|
|
|
|
2017-07-09 21:22:31 +00:00
|
|
|
// Replace this with ID list from twist.moe later
|
2017-07-11 11:12:10 +00:00
|
|
|
twistAnime, err := twist.GetAnimeIndex()
|
2017-07-10 14:58:34 +00:00
|
|
|
arn.PanicOnError(err)
|
2017-11-02 21:17:11 +00:00
|
|
|
idList := arn.IDList(twistAnime.KitsuIDs())
|
2017-07-10 14:58:34 +00:00
|
|
|
|
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-10 14:58:34 +00:00
|
|
|
|
2017-07-11 11:12:10 +00:00
|
|
|
for count, animeID := range idList {
|
|
|
|
anime, animeErr := arn.GetAnime(animeID)
|
2017-07-10 14:58:34 +00:00
|
|
|
|
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
|
|
|
|
}
|
2017-07-09 21:22:31 +00:00
|
|
|
|
2017-07-10 14:58:34 +00:00
|
|
|
// Log
|
2017-07-11 11:12:10 +00:00
|
|
|
fmt.Fprintf(os.Stdout, "[%d / %d] ", count+1, len(idList))
|
2017-07-10 14:58:34 +00:00
|
|
|
|
2017-07-11 11:26:53 +00:00
|
|
|
// Refresh
|
|
|
|
anime.RefreshEpisodes()
|
2017-07-09 21:22:31 +00:00
|
|
|
|
2017-07-11 11:26:53 +00:00
|
|
|
// Ok
|
|
|
|
color.Green("Found %d episodes for anime %s", len(anime.Episodes().Items), animeID)
|
2017-07-09 21:22:31 +00:00
|
|
|
|
2017-07-11 11:26:53 +00:00
|
|
|
// Wait for rate limiter
|
|
|
|
<-rateLimiter.C
|
2017-07-09 21:22:31 +00:00
|
|
|
}
|
|
|
|
}
|