74 lines
1.4 KiB
Go
Raw Normal View History

2017-07-01 21:08:12 +00:00
package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"strconv"
"github.com/animenotifier/arn"
)
// OldMatch ...
type OldMatch struct {
2017-07-01 21:33:41 +00:00
ID int `json:"id"`
ServiceID int `json:"providerId"`
Title string `json:"title"`
ServiceTitle string `json:"providerTitle"`
Similarity float64 `json:"similarity"`
Edited string `json:"edited"`
EditedBy string `json:"editedBy"`
2017-07-01 21:08:12 +00:00
}
func main() {
matches := []OldMatch{}
data, _ := ioutil.ReadFile("MatchKitsu.json")
json.Unmarshal(data, &matches)
for _, match := range matches {
// Custom anime in 3.0
if match.ID >= 1000000 {
continue
}
// New match type
2017-07-01 21:33:41 +00:00
newMatch := &arn.AniListToAnime{
AnimeID: strconv.Itoa(match.ServiceID),
ServiceID: strconv.Itoa(match.ID),
Similarity: match.Similarity,
2017-07-01 21:08:12 +00:00
Edited: match.Edited,
EditedBy: match.EditedBy,
}
// Get anime
anime, err := arn.GetAnime(newMatch.AnimeID)
if err != nil {
continue
}
2017-07-01 21:33:41 +00:00
if anime.GetMapping("anilist/anime") != "" {
continue
}
2017-07-01 21:08:12 +00:00
anime.Mappings = append(anime.Mappings, &arn.Mapping{
Service: "anilist/anime",
2017-07-01 21:33:41 +00:00
ServiceID: newMatch.ServiceID,
2017-07-01 21:08:12 +00:00
Created: newMatch.Edited,
CreatedBy: newMatch.EditedBy,
})
// Save
fmt.Println(anime.Title.Canonical)
arn.PanicOnError(anime.Save())
2017-07-01 21:33:41 +00:00
arn.PanicOnError(arn.DB.Set("AniListToAnime", newMatch.ServiceID, newMatch))
2017-07-01 21:08:12 +00:00
}
}
// AnilistToAnime
/*
AnimeID
2017-07-01 21:33:41 +00:00
ServiceID
2017-07-01 21:08:12 +00:00
*/