From ecc9b90a2112340ae807a9cb3abdf5b627533688 Mon Sep 17 00:00:00 2001 From: Eduard Urbach Date: Thu, 29 Jun 2017 16:04:09 +0200 Subject: [PATCH] Added patch to automatically set status to correct value --- patches/anime-list-item-status/main.go | 40 ++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 patches/anime-list-item-status/main.go diff --git a/patches/anime-list-item-status/main.go b/patches/anime-list-item-status/main.go new file mode 100644 index 00000000..97233c47 --- /dev/null +++ b/patches/anime-list-item-status/main.go @@ -0,0 +1,40 @@ +package main + +import ( + "fmt" + + "github.com/animenotifier/arn" + "github.com/fatih/color" +) + +func main() { + color.Yellow("Setting list item status to correct value") + + // Get a stream of all anime lists + allAnimeLists, err := arn.StreamAnimeLists() + + if err != nil { + panic(err) + } + + // Iterate over the stream + for animeList := range allAnimeLists { + fmt.Println(animeList.User().Nick) + + for _, item := range animeList.Items { + if item.Status == arn.AnimeListStatusPlanned && item.Episodes > 0 { + item.Status = arn.AnimeListStatusWatching + } + + if item.Anime().Status == "finished" && item.Anime().EpisodeCount != 0 && item.Episodes >= item.Anime().EpisodeCount { + item.Status = arn.AnimeListStatusCompleted + item.Episodes = item.Anime().EpisodeCount + } + } + + err := animeList.Save() + arn.PanicOnError(err) + } + + color.Green("Finished.") +}