diff --git a/patches/import-mal-genres/import-mal-genres.go b/patches/import-mal-anime-data/import-mal-anime-data.go similarity index 53% rename from patches/import-mal-genres/import-mal-genres.go rename to patches/import-mal-anime-data/import-mal-anime-data.go index 367c0e60..35f8206e 100644 --- a/patches/import-mal-genres/import-mal-genres.go +++ b/patches/import-mal-anime-data/import-mal-anime-data.go @@ -37,6 +37,38 @@ func sync(anime *arn.Anime, malID string) { } malAnime := obj.(*mal.Anime) - anime.Genres = malAnime.Genres + + 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 + } + anime.Save() } diff --git a/patches/import-mal-files/import-mal-files.go b/patches/import-mal-files/import-mal-files.go deleted file mode 100644 index f9ba345a..00000000 --- a/patches/import-mal-files/import-mal-files.go +++ /dev/null @@ -1,67 +0,0 @@ -package main - -import ( - "errors" - "fmt" - "os" - "path/filepath" - "strings" - - "github.com/animenotifier/mal" - - "github.com/aerogo/nano" - "github.com/animenotifier/mal/parser" -) - -var node = nano.New(5000) -var db = node.Namespace("mal").RegisterTypes((*mal.Anime)(nil)) - -func main() { - defer node.Close() - - if true { - filepath.Walk("data", func(name string, info os.FileInfo, err error) error { - if err != nil { - fmt.Println(err) - return err - } - - if info.IsDir() { - return nil - } - - if !strings.HasSuffix(name, "-main.html") { - return nil - } - - return readFile(name) - }) - } else { - readFile("data/anime-1-main.html") - } -} - -func readFile(name string) error { - file, err := os.Open(name) - defer file.Close() - - if err != nil { - fmt.Println(err) - return err - } - - anime, err := malparser.ParseAnime(file) - - if err != nil { - fmt.Println(err) - return err - } - - if anime.ID == "" { - return errors.New("Empty ID") - } - - fmt.Println(anime.ID, anime.URL) - db.Set("Anime", anime.ID, anime) - return nil -}