Airing anime page

This commit is contained in:
Eduard Urbach 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 {

View File

@ -2,4 +2,4 @@ component AnimeGrid(animeList []*arn.Anime)
.anime-grid
each anime in animeList
a.anime-grid-cell.ajax(href="/anime/" + toString(anime.ID))
img.anime-grid-image(src=anime.Image, alt=anime.Title.Romaji, title=anime.Title.Romaji + " (" + toString(anime.Watching()) + ")")
img.anime-grid-image(src=anime.Image.Small, alt=anime.Title.Romaji, title=anime.Title.Romaji + " (" + toString(anime.Watching()) + ")")

View File

@ -2,17 +2,20 @@ package airing
import (
"github.com/aerogo/aero"
"github.com/animenotifier/arn"
"github.com/animenotifier/notify.moe/components"
)
// Get ...
func Get(ctx *aero.Context) string {
// airingAnimeCache := new(arn.AiringAnimeCache)
// err := arn.GetObject("Cache", "airingAnime", airingAnimeCache)
var cache arn.ListOfIDs
err := arn.GetObject("Cache", "airing anime", &cache)
// if err != nil {
// return ctx.Error(500, "Couldn't fetch airing anime", err)
// }
airing, err := arn.GetAiringAnimeCached()
// return ctx.HTML(components.Airing(airingAnimeCache.Anime))
return ctx.HTML("Coming soon.")
if err != nil {
return ctx.Error(500, "Couldn't fetch airing anime", err)
}
return ctx.HTML(components.Airing(airing))
}