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")
|
|
|
|
|
|
|
|
animeChan, err := arn.AllAnime()
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
color.Red("Failed fetching anime channel")
|
|
|
|
color.Red(err.Error())
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
var animeList []*arn.Anime
|
|
|
|
|
|
|
|
for anime := range animeChan {
|
|
|
|
animeList = append(animeList, anime)
|
|
|
|
}
|
|
|
|
|
|
|
|
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-06-23 22:12:05 +00:00
|
|
|
// Change size of anime list to 10
|
2017-06-23 22:23:09 +00:00
|
|
|
animeList = animeList[:maxPopularAnime]
|
2017-06-23 22:12:05 +00:00
|
|
|
|
|
|
|
// Convert to small anime list
|
|
|
|
cache := &arn.ListOfIDs{}
|
|
|
|
|
|
|
|
for _, anime := range animeList {
|
|
|
|
cache.IDList = append(cache.IDList, anime.ID)
|
|
|
|
}
|
|
|
|
|
|
|
|
println(len(cache.IDList))
|
|
|
|
|
|
|
|
saveErr := arn.DB.Set("Cache", "popular anime", cache)
|
|
|
|
|
|
|
|
if saveErr != nil {
|
|
|
|
color.Red("Error saving popular anime")
|
|
|
|
color.Red(saveErr.Error())
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
color.Green("Finished.")
|
|
|
|
}
|