75 lines
1.3 KiB
Go
Raw Normal View History

2017-11-29 05:48:58 +00:00
package main
import (
"fmt"
"github.com/animenotifier/arn"
"github.com/animenotifier/mal"
"github.com/fatih/color"
)
var malDB = arn.Node.Namespace("mal").RegisterTypes((*mal.Anime)(nil))
func main() {
defer arn.Node.Close()
color.Yellow("Importing genres")
for anime := range arn.StreamAnime() {
malID := anime.GetMapping("myanimelist/anime")
if malID == "" {
continue
}
2017-11-29 05:52:50 +00:00
fmt.Println(anime.Title.Canonical, malID)
2017-11-29 05:48:58 +00:00
sync(anime, malID)
}
color.Green("Finished importing genres")
}
func sync(anime *arn.Anime, malID string) {
obj, err := malDB.Get("Anime", malID)
if err != nil {
fmt.Println(err)
return
}
malAnime := obj.(*mal.Anime)
2018-04-03 20:35:49 +00:00
if len(anime.Genres) == 0 {
anime.Genres = malAnime.Genres
}
if anime.EpisodeCount == 0 {
anime.EpisodeCount = malAnime.EpisodeCount
}
if anime.EpisodeLength == 0 {
anime.EpisodeLength = malAnime.EpisodeLength
}
if anime.StartDate == "" {
anime.StartDate = malAnime.StartDate
}
if anime.EndDate == "" {
anime.EndDate = malAnime.EndDate
}
if anime.Source == "" {
anime.Source = malAnime.Source
}
if anime.Title.Japanese == "" {
anime.Title.Japanese = malAnime.JapaneseTitle
}
if anime.Title.English == "" {
anime.Title.English = malAnime.EnglishTitle
}
2017-11-29 05:52:50 +00:00
anime.Save()
2017-11-29 05:48:58 +00:00
}