Added MAL import

This commit is contained in:
Eduard Urbach 2017-11-29 06:19:34 +01:00
parent 4460b10ea3
commit 694b62fdef

View File

@ -0,0 +1,67 @@
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
}