2017-06-23 22:12:05 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"sort"
|
|
|
|
|
|
|
|
"github.com/animenotifier/arn"
|
|
|
|
"github.com/fatih/color"
|
|
|
|
)
|
|
|
|
|
2017-06-23 22:23:09 +00:00
|
|
|
const maxPopularAnime = 10
|
|
|
|
|
2017-06-23 22:12:05 +00:00
|
|
|
// Note this is using the airing-anime as a template with modfications
|
|
|
|
// made to it.
|
|
|
|
func main() {
|
|
|
|
color.Yellow("Caching popular anime")
|
|
|
|
|
2017-07-01 00:14:14 +00:00
|
|
|
// Fetch all anime
|
2017-06-27 10:39:41 +00:00
|
|
|
animeList, err := arn.AllAnime()
|
2017-07-01 00:14:14 +00:00
|
|
|
arn.PanicOnError(err)
|
2017-06-23 22:12:05 +00:00
|
|
|
|
2017-07-01 00:14:14 +00:00
|
|
|
// Overall
|
2017-06-23 22:12:05 +00:00
|
|
|
sort.Slice(animeList, func(i, j int) bool {
|
|
|
|
return animeList[i].Rating.Overall > animeList[j].Rating.Overall
|
|
|
|
})
|
2017-06-23 22:36:07 +00:00
|
|
|
|
2017-07-01 00:14:14 +00:00
|
|
|
saveAs(animeList[:maxPopularAnime], "best anime overall")
|
2017-06-23 22:12:05 +00:00
|
|
|
|
2017-07-01 00:14:14 +00:00
|
|
|
// Story
|
|
|
|
sort.Slice(animeList, func(i, j int) bool {
|
|
|
|
return animeList[i].Rating.Story > animeList[j].Rating.Story
|
|
|
|
})
|
2017-06-23 22:12:05 +00:00
|
|
|
|
2017-07-01 00:14:14 +00:00
|
|
|
saveAs(animeList[:maxPopularAnime], "best anime story")
|
2017-06-23 22:12:05 +00:00
|
|
|
|
2017-07-01 00:14:14 +00:00
|
|
|
// Visuals
|
|
|
|
sort.Slice(animeList, func(i, j int) bool {
|
|
|
|
return animeList[i].Rating.Visuals > animeList[j].Rating.Visuals
|
|
|
|
})
|
2017-06-23 22:12:05 +00:00
|
|
|
|
2017-07-01 00:14:14 +00:00
|
|
|
saveAs(animeList[:maxPopularAnime], "best anime visuals")
|
2017-06-23 22:12:05 +00:00
|
|
|
|
2017-07-01 00:14:14 +00:00
|
|
|
// Soundtrack
|
|
|
|
sort.Slice(animeList, func(i, j int) bool {
|
|
|
|
return animeList[i].Rating.Soundtrack > animeList[j].Rating.Soundtrack
|
|
|
|
})
|
|
|
|
|
|
|
|
saveAs(animeList[:maxPopularAnime], "best anime soundtrack")
|
2017-06-23 22:12:05 +00:00
|
|
|
|
2017-07-01 00:14:14 +00:00
|
|
|
// Done.
|
2017-06-23 22:12:05 +00:00
|
|
|
color.Green("Finished.")
|
|
|
|
}
|
2017-07-01 00:14:14 +00:00
|
|
|
|
|
|
|
// Convert to ListOfIDs and save in cache.
|
|
|
|
func saveAs(list []*arn.Anime, cacheKey string) {
|
|
|
|
cache := &arn.ListOfIDs{}
|
|
|
|
|
|
|
|
for _, anime := range list {
|
|
|
|
cache.IDList = append(cache.IDList, anime.ID)
|
|
|
|
}
|
|
|
|
|
|
|
|
arn.PanicOnError(arn.DB.Set("Cache", cacheKey, cache))
|
|
|
|
}
|