Improved importer

This commit is contained in:
Eduard Urbach 2017-07-01 23:33:41 +02:00
parent f3d55e224a
commit dfa72d5df0

View File

@ -11,26 +11,15 @@ import (
// OldMatch ... // OldMatch ...
type OldMatch struct { type OldMatch struct {
ID int `json:"id"` ID int `json:"id"`
ProviderID int `json:"providerId"` ServiceID int `json:"providerId"`
Title string `json:"title"` Title string `json:"title"`
ProviderTitle string `json:"providerTitle"` ServiceTitle string `json:"providerTitle"`
Similarity float64 `json:"similarity"` Similarity float64 `json:"similarity"`
Edited string `json:"edited"` Edited string `json:"edited"`
EditedBy string `json:"editedBy"` EditedBy string `json:"editedBy"`
} }
// ProviderMatch ...
type ProviderMatch struct {
AnimeID string `json:"animeId"`
ProviderID string `json:"providerId"`
Edited string `json:"edited"`
EditedBy string `json:"editedBy"`
}
// AniListToAnime ...
type AniListToAnime ProviderMatch
func main() { func main() {
matches := []OldMatch{} matches := []OldMatch{}
data, _ := ioutil.ReadFile("MatchKitsu.json") data, _ := ioutil.ReadFile("MatchKitsu.json")
@ -43,9 +32,10 @@ func main() {
} }
// New match type // New match type
newMatch := &ProviderMatch{ newMatch := &arn.AniListToAnime{
AnimeID: strconv.Itoa(match.ProviderID), AnimeID: strconv.Itoa(match.ServiceID),
ProviderID: strconv.Itoa(match.ID), ServiceID: strconv.Itoa(match.ID),
Similarity: match.Similarity,
Edited: match.Edited, Edited: match.Edited,
EditedBy: match.EditedBy, EditedBy: match.EditedBy,
} }
@ -57,9 +47,13 @@ func main() {
continue continue
} }
if anime.GetMapping("anilist/anime") != "" {
continue
}
anime.Mappings = append(anime.Mappings, &arn.Mapping{ anime.Mappings = append(anime.Mappings, &arn.Mapping{
Service: "anilist/anime", Service: "anilist/anime",
ServiceID: newMatch.ProviderID, ServiceID: newMatch.ServiceID,
Created: newMatch.Edited, Created: newMatch.Edited,
CreatedBy: newMatch.EditedBy, CreatedBy: newMatch.EditedBy,
}) })
@ -67,13 +61,13 @@ func main() {
// Save // Save
fmt.Println(anime.Title.Canonical) fmt.Println(anime.Title.Canonical)
arn.PanicOnError(anime.Save()) arn.PanicOnError(anime.Save())
arn.PanicOnError(arn.DB.Set("AniListToAnime", newMatch.ProviderID, newMatch)) arn.PanicOnError(arn.DB.Set("AniListToAnime", newMatch.ServiceID, newMatch))
} }
} }
// AnilistToAnime // AnilistToAnime
/* /*
AnimeID AnimeID
ProviderID ServiceID
*/ */