Added airing anime cache
This commit is contained in:
parent
73b68c0a0f
commit
3fe3d00134
36
jobs/airing-anime.go
Normal file
36
jobs/airing-anime.go
Normal 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
|
||||||
|
}
|
||||||
|
}
|
15
main.go
15
main.go
@ -4,8 +4,8 @@ import (
|
|||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
|
||||||
"github.com/aerogo/aero"
|
"github.com/aerogo/aero"
|
||||||
"github.com/animenotifier/arn"
|
|
||||||
"github.com/animenotifier/notify.moe/components"
|
"github.com/animenotifier/notify.moe/components"
|
||||||
|
"github.com/animenotifier/notify.moe/jobs"
|
||||||
"github.com/animenotifier/notify.moe/pages/airing"
|
"github.com/animenotifier/notify.moe/pages/airing"
|
||||||
"github.com/animenotifier/notify.moe/pages/anime"
|
"github.com/animenotifier/notify.moe/pages/anime"
|
||||||
"github.com/animenotifier/notify.moe/pages/dashboard"
|
"github.com/animenotifier/notify.moe/pages/dashboard"
|
||||||
@ -24,11 +24,14 @@ var app = aero.New()
|
|||||||
func main() {
|
func main() {
|
||||||
app.SetStyle(components.BundledCSS)
|
app.SetStyle(components.BundledCSS)
|
||||||
|
|
||||||
user, _ := arn.GetUserByNick("Akyoto")
|
// user, _ := arn.GetUserByNick("Akyoto")
|
||||||
user.CoverImage.URL = "https://www.pixelstalk.net/wp-content/uploads/2016/10/Hanyijie-sky-scenery-ship-anime-art-1920x1080.jpg"
|
// user.CoverImage.URL = "https://www.pixelstalk.net/wp-content/uploads/2016/10/Hanyijie-sky-scenery-ship-anime-art-1920x1080.jpg"
|
||||||
user.CoverImage.Position.X = "50%"
|
// user.CoverImage.Position.X = "50%"
|
||||||
user.CoverImage.Position.Y = "0%"
|
// user.CoverImage.Position.Y = "0%"
|
||||||
user.Save()
|
// user.Save()
|
||||||
|
|
||||||
|
// Background jobs
|
||||||
|
go jobs.AiringAnime()
|
||||||
|
|
||||||
scripts, _ := ioutil.ReadFile("temp/scripts.js")
|
scripts, _ := ioutil.ReadFile("temp/scripts.js")
|
||||||
js := string(scripts)
|
js := string(scripts)
|
||||||
|
@ -1,21 +1,15 @@
|
|||||||
package airing
|
package airing
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"sort"
|
|
||||||
|
|
||||||
"github.com/aerogo/aero"
|
"github.com/aerogo/aero"
|
||||||
"github.com/animenotifier/arn"
|
"github.com/animenotifier/arn"
|
||||||
"github.com/animenotifier/notify.moe/components"
|
"github.com/animenotifier/notify.moe/components"
|
||||||
|
"github.com/animenotifier/notify.moe/jobs"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Get ...
|
// Get ...
|
||||||
func Get(ctx *aero.Context) string {
|
func Get(ctx *aero.Context) string {
|
||||||
animeList, err := arn.GetAiringAnime()
|
var airingAnimeCache jobs.AiringAnimeCache
|
||||||
|
arn.GetObject("Cache", "airingAnime", &airingAnimeCache)
|
||||||
if err != nil {
|
return ctx.HTML(components.Airing(airingAnimeCache.Anime))
|
||||||
return ctx.Error(500, "Failed fetching airing anime", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
sort.Sort(arn.AnimeByPopularity(animeList))
|
|
||||||
return ctx.HTML(components.Airing(animeList))
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user