47 lines
871 B
Go
Raw Normal View History

package main
2016-11-23 05:42:51 +00:00
import (
"fmt"
2016-11-23 05:42:51 +00:00
"sort"
"github.com/animenotifier/arn"
"github.com/fatih/color"
)
// AiringAnime ...
func AiringAnime() {
fmt.Println("Running background job: Airing Anime")
2016-11-23 05:42:51 +00:00
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", &arn.AiringAnimeCacheSmall{
2016-11-23 09:07:02 +00:00
Anime: animeListSmall,
2016-11-23 05:42:51 +00:00
})
if saveErr != nil {
color.Red("Error saving airing anime")
color.Red(saveErr.Error())
return
}
}