New MAL import

This commit is contained in:
Eduard Urbach 2018-04-03 22:35:49 +02:00
parent 2f2bc54c3e
commit a8f9093430
2 changed files with 33 additions and 68 deletions

View File

@ -37,6 +37,38 @@ func sync(anime *arn.Anime, malID string) {
}
malAnime := obj.(*mal.Anime)
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()
}

View File

@ -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
}