54 lines
1007 B
Go
Raw Normal View History

2016-11-23 05:42:51 +00:00
package jobs
import (
"sort"
"github.com/animenotifier/arn"
"github.com/fatih/color"
)
// AiringAnimeCache ...
type AiringAnimeCache struct {
Anime []*arn.Anime `json:"anime"`
}
2016-11-23 09:07:02 +00:00
// AiringAnimeCacheSmall ...
type AiringAnimeCacheSmall struct {
Anime []*arn.AnimeSmall `json:"anime"`
}
2016-11-23 05:42:51 +00:00
// 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))
2016-11-23 09:07:02 +00:00
// Convert to small anime list
var animeListSmall []*arn.AnimeSmall
for _, anime := range animeList {
animeListSmall = append(animeListSmall, &arn.AnimeSmall{
ID: anime.ID,
Title: anime.Title,
Image: anime.Image,
Watching: anime.Watching,
})
}
saveErr := arn.SetObject("Cache", "airingAnime", &AiringAnimeCacheSmall{
Anime: animeListSmall,
2016-11-23 05:42:51 +00:00
})
if saveErr != nil {
color.Red("Error saving airing anime")
color.Red(saveErr.Error())
return
}
}