53 lines
925 B
Go
Raw Normal View History

2017-11-12 16:40:25 +00:00
package main
import (
"fmt"
"time"
"github.com/animenotifier/jikan"
"github.com/animenotifier/arn"
"github.com/fatih/color"
)
var jikanDB = arn.Node.Namespace("jikan")
func main() {
color.Yellow("Syncing with Jikan API")
defer arn.Node.Close()
count := 0
for anime := range arn.StreamAnime() {
malID := anime.GetMapping("myanimelist/anime")
if malID != "" {
sync(anime, malID)
count++
}
}
color.Green("Finished syncing %d anime.", count)
// Give OS some time to write buffers, just to be safe
time.Sleep(10 * time.Second)
}
func sync(anime *arn.Anime, malID string) {
fmt.Printf("%s %s (MAL: %s)\n", anime.ID, anime.Title.Canonical, malID)
2017-11-13 20:38:16 +00:00
if jikanDB.Exists("Anime", malID) {
return
}
2017-11-12 16:40:25 +00:00
2017-11-29 01:16:20 +00:00
time.Sleep(2 * time.Second)
2017-11-13 20:38:16 +00:00
jikanAnime, err := jikan.GetAnime(malID)
2017-11-13 19:42:53 +00:00
2017-11-13 20:38:16 +00:00
if err == nil {
jikanDB.Set("Anime", malID, jikanAnime)
return
2017-11-12 16:40:25 +00:00
}
2017-11-13 20:38:16 +00:00
2017-11-13 21:17:26 +00:00
fmt.Printf("Error fetching %s: %v\n", malID, err)
2017-11-12 16:40:25 +00:00
}