85 lines
1.9 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()
2018-04-03 20:36:32 +00:00
color.Yellow("Importing MAL data")
2017-11-29 05:48:58 +00:00
for anime := range arn.StreamAnime() {
malID := anime.GetMapping("myanimelist/anime")
if malID == "" {
continue
}
sync(anime, malID)
}
2018-04-03 20:36:32 +00:00
color.Green("Finished importing MAL data")
2017-11-29 05:48:58 +00:00
}
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
2018-04-07 09:09:08 +00:00
// Log title
fmt.Printf("%s %s\n", color.CyanString(anime.Title.Canonical), malID)
2018-04-03 20:53:53 +00:00
if len(anime.Genres) == 0 && len(malAnime.Genres) > 0 {
fmt.Println("Genres:", malAnime.Genres)
2018-04-03 20:35:49 +00:00
anime.Genres = malAnime.Genres
}
2018-04-03 20:53:53 +00:00
if anime.EpisodeCount == 0 && malAnime.EpisodeCount != 0 {
fmt.Println("EpisodeCount:", malAnime.EpisodeCount)
2018-04-03 20:35:49 +00:00
anime.EpisodeCount = malAnime.EpisodeCount
}
2018-04-03 20:53:53 +00:00
if anime.EpisodeLength == 0 && malAnime.EpisodeLength != 0 {
fmt.Println("EpisodeLength:", malAnime.EpisodeLength)
2018-04-03 20:35:49 +00:00
anime.EpisodeLength = malAnime.EpisodeLength
}
2018-04-03 20:53:53 +00:00
if anime.StartDate == "" && malAnime.StartDate != "" {
fmt.Println("StartDate:", malAnime.StartDate)
2018-04-03 20:35:49 +00:00
anime.StartDate = malAnime.StartDate
}
2018-04-03 20:53:53 +00:00
if anime.EndDate == "" && malAnime.EndDate != "" {
fmt.Println("EndDate:", malAnime.EndDate)
2018-04-03 20:35:49 +00:00
anime.EndDate = malAnime.EndDate
}
2018-04-03 20:53:53 +00:00
if anime.Source == "" && malAnime.Source != "" {
fmt.Println("Source:", malAnime.Source)
2018-04-03 20:35:49 +00:00
anime.Source = malAnime.Source
}
2018-04-03 20:53:53 +00:00
if anime.Title.Japanese == "" && malAnime.JapaneseTitle != "" {
fmt.Println("JapaneseTitle:", malAnime.JapaneseTitle)
2018-04-03 20:35:49 +00:00
anime.Title.Japanese = malAnime.JapaneseTitle
}
2018-04-03 20:53:53 +00:00
if anime.Title.English == "" && malAnime.EnglishTitle != "" {
fmt.Println("EnglishTitle:", malAnime.EnglishTitle)
2018-04-03 20:35:49 +00:00
anime.Title.English = malAnime.EnglishTitle
}
2018-04-03 22:17:55 +00:00
anime.Save()
2017-11-29 05:48:58 +00:00
}