2017-06-06 20:08:43 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2017-06-07 19:12:59 +00:00
|
|
|
"sort"
|
|
|
|
|
2017-06-06 20:08:43 +00:00
|
|
|
"github.com/animenotifier/arn"
|
|
|
|
"github.com/fatih/color"
|
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
color.Yellow("Caching airing anime")
|
|
|
|
|
|
|
|
animeList, err := arn.GetAiringAnime()
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
color.Red("Failed fetching airing anime")
|
|
|
|
color.Red(err.Error())
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2017-06-07 19:12:59 +00:00
|
|
|
sort.Slice(animeList, func(i, j int) bool {
|
2017-06-08 09:51:34 +00:00
|
|
|
return animeList[i].Rating.Overall > animeList[j].Rating.Overall
|
2017-06-07 19:12:59 +00:00
|
|
|
})
|
2017-06-06 20:08:43 +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.SetObject("Cache", "airing anime", cache)
|
|
|
|
|
|
|
|
if saveErr != nil {
|
|
|
|
color.Red("Error saving airing anime")
|
|
|
|
color.Red(saveErr.Error())
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
color.Green("Finished.")
|
|
|
|
}
|