Added airing anime cache

This commit is contained in:
2016-11-23 14:42:51 +09:00
parent 73b68c0a0f
commit 3fe3d00134
3 changed files with 49 additions and 16 deletions

36
jobs/airing-anime.go Normal file
View File

@ -0,0 +1,36 @@
package jobs
import (
"sort"
"github.com/animenotifier/arn"
"github.com/fatih/color"
)
// AiringAnimeCache ...
type AiringAnimeCache struct {
Anime []*arn.Anime `json:"anime"`
}
// AiringAnime ...
func AiringAnime() {
animeList, err := arn.GetAiringAnime()
if err != nil {
color.Red("Failed fetching airing anime")
color.Red(err.Error())
return
}
sort.Sort(arn.AnimeByPopularity(animeList))
saveErr := arn.SetObject("Cache", "airingAnime", &AiringAnimeCache{
Anime: animeList,
})
if saveErr != nil {
color.Red("Error saving airing anime")
color.Red(saveErr.Error())
return
}
}