Anime episodes stored under a different table

This commit is contained in:
2017-07-10 16:58:34 +02:00
parent 29842b3ccc
commit 8037edcb67
11 changed files with 112 additions and 63 deletions

View File

@ -1,21 +1,44 @@
package main
import (
"fmt"
"os"
"sort"
"strings"
"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
animeIDs := []string{
"13274",
"10902",
}
currentAnime, err := arn.FilterAnime(func(anime *arn.Anime) bool {
return anime.Status == "current"
})
arn.PanicOnError(err)
for _, animeID := range animeIDs {
color.Yellow("Refreshing twist.moe links for %d anime", len(currentAnime))
for count, anime := range currentAnime {
// Wait for rate limiter
<-rateLimiter.C
// anime, animeErr := arn.GetAnime(animeID)
// if animeErr != nil {
// color.Red("Error fetching anime from the database with ID %s: %v", animeID, animeErr)
// continue
// }
animeID := anime.ID
// Log
fmt.Fprintf(os.Stdout, "[%d / %d] ", count+1, len(currentAnime))
// Get twist.moe feed
feed, err := twist.GetFeedByKitsuID(animeID)
if err != nil {
@ -30,6 +53,22 @@ func main() {
return episodes[a].Number < episodes[b].Number
})
arn.PrettyPrint(episodes)
for _, episode := range episodes {
arnEpisode := anime.EpisodeByNumber(episode.Number)
if arnEpisode == nil {
color.Red("Anime %s Episode %d not found", anime.ID, episode.Number)
continue
}
if arnEpisode.Links == nil {
arnEpisode.Links = map[string]string{}
}
arnEpisode.Links["twist.moe"] = strings.Replace(episode.Link, "https://test.twist.moe/", "https://twist.moe/", 1)
}
arn.PanicOnError(anime.Episodes().Save())
color.Green("Found %d episodes for anime %s", len(episodes), animeID)
}
}