Save anime relations
This commit is contained in:
parent
dea7ab42fa
commit
011ca84bd0
@ -4,6 +4,8 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/animenotifier/arn"
|
||||||
|
|
||||||
"github.com/animenotifier/kitsu"
|
"github.com/animenotifier/kitsu"
|
||||||
"github.com/fatih/color"
|
"github.com/fatih/color"
|
||||||
)
|
)
|
||||||
@ -12,6 +14,7 @@ func main() {
|
|||||||
color.Yellow("Syncing media relations with Kitsu DB")
|
color.Yellow("Syncing media relations with Kitsu DB")
|
||||||
|
|
||||||
kitsuMediaRelations := kitsu.StreamMediaRelations()
|
kitsuMediaRelations := kitsu.StreamMediaRelations()
|
||||||
|
relations := map[arn.AnimeID]*arn.AnimeRelations{}
|
||||||
|
|
||||||
for mediaRelation := range kitsuMediaRelations {
|
for mediaRelation := range kitsuMediaRelations {
|
||||||
// We only care about anime for now
|
// We only care about anime for now
|
||||||
@ -20,15 +23,45 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
relationType := strings.Replace(mediaRelation.Attributes.Role, "_", " ", -1)
|
relationType := strings.Replace(mediaRelation.Attributes.Role, "_", " ", -1)
|
||||||
|
animeID := mediaRelation.Relationships.Source.Data.ID
|
||||||
|
destinationAnimeID := mediaRelation.Relationships.Destination.Data.ID
|
||||||
|
|
||||||
fmt.Printf(
|
fmt.Printf(
|
||||||
"%s %s has a %s which is %s %s\n",
|
"%s %s has %s which is %s %s\n",
|
||||||
mediaRelation.Relationships.Source.Data.Type,
|
mediaRelation.Relationships.Source.Data.Type,
|
||||||
mediaRelation.Relationships.Source.Data.ID,
|
animeID,
|
||||||
color.GreenString(relationType),
|
color.GreenString(relationType),
|
||||||
mediaRelation.Relationships.Destination.Data.Type,
|
mediaRelation.Relationships.Destination.Data.Type,
|
||||||
mediaRelation.Relationships.Destination.Data.ID,
|
destinationAnimeID,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
relationsList, found := relations[animeID]
|
||||||
|
|
||||||
|
if !found {
|
||||||
|
relationsList = &arn.AnimeRelations{
|
||||||
|
AnimeID: animeID,
|
||||||
|
Items: []*arn.AnimeRelation{},
|
||||||
|
}
|
||||||
|
relations[animeID] = relationsList
|
||||||
|
}
|
||||||
|
|
||||||
|
relationsList.Items = append(relationsList.Items, &arn.AnimeRelation{
|
||||||
|
AnimeID: destinationAnimeID,
|
||||||
|
Type: relationType,
|
||||||
|
})
|
||||||
|
|
||||||
|
// for _, item := range relationsList.Items {
|
||||||
|
// fmt.Println("*", item.Type, item.AnimeID)
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
|
||||||
|
// Save relations map
|
||||||
|
for _, animeRelations := range relations {
|
||||||
|
err := animeRelations.Save()
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
color.Red(err.Error())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
color.Green("Finished.")
|
color.Green("Finished.")
|
||||||
|
Loading…
Reference in New Issue
Block a user