Airing anime page

This commit is contained in:
2017-06-06 22:08:43 +02:00
parent b305be5ae4
commit 2f0d8c9636
6 changed files with 54 additions and 75 deletions

View File

@ -1,46 +0,0 @@
// package main
// import (
// "fmt"
// "sort"
// "github.com/animenotifier/arn"
// "github.com/fatih/color"
// )
// // AiringAnime ...
// func AiringAnime() {
// fmt.Println("Running background job: Airing Anime")
// animeList, err := arn.GetAiringAnime()
// if err != nil {
// color.Red("Failed fetching airing anime")
// color.Red(err.Error())
// return
// }
// sort.Sort(arn.AnimeByPopularity(animeList))
// // 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{
// Anime: animeListSmall,
// })
// if saveErr != nil {
// color.Red("Error saving airing anime")
// color.Red(saveErr.Error())
// return
// }
// }

View File

@ -0,0 +1,39 @@
package main
import (
"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
}
// sort.Slice
// 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.")
}

View File

@ -1,18 +0,0 @@
package main
import "time"
func main() {
// Background jobs
go func() {
for {
AiringAnime()
time.Sleep(time.Duration(2) * time.Second)
}
}()
// Main loop
for {
time.Sleep(time.Duration(10) * time.Second)
}
}

View File

@ -42,17 +42,18 @@ func sync(data *kitsu.Anime) {
anime.EndDate = attr.EndDate
anime.EpisodeCount = attr.EpisodeCount
anime.EpisodeLength = attr.EpisodeLength
anime.Status = attr.Status
anime.NSFW = attr.Nsfw
anime.Summary = arn.FixAnimeDescription(attr.Synopsis)
if data.Attributes.YoutubeVideoID != "" {
if attr.YoutubeVideoID != "" {
anime.Trailers = append(anime.Trailers, arn.AnimeTrailer{
Service: "Youtube",
VideoID: data.Attributes.YoutubeVideoID,
VideoID: attr.YoutubeVideoID,
})
}
err := anime.Save()
status := ""
if err == nil {