Anime character refresh

This commit is contained in:
Eduard Urbach 2017-07-13 08:23:20 +02:00
parent db4d362fb3
commit d6155bf3a1
9 changed files with 54 additions and 9 deletions

View File

@ -1,14 +1,30 @@
package main package main
import ( import (
"fmt"
"time"
"github.com/animenotifier/arn" "github.com/animenotifier/arn"
"github.com/fatih/color" "github.com/fatih/color"
) )
func main() { func main() {
anime, _ := arn.GetAnime("6887") color.Yellow("Refreshing anime characters...")
err := anime.RefreshAnimeCharacters()
arn.PanicOnError(err) rateLimiter := time.NewTicker(500 * time.Millisecond)
for anime := range arn.MustStreamAnime() {
<-rateLimiter.C
chars, err := anime.RefreshAnimeCharacters()
if err != nil {
color.Red(err.Error())
continue
}
fmt.Printf("%s %s (%d characters)\n", anime.ID, anime.Title.Canonical, len(chars.Items))
}
color.Green("Finished.") color.Green("Finished.")
} }

View File

@ -18,7 +18,7 @@ func main() {
ID: kitsuCharacter.ID, ID: kitsuCharacter.ID,
Name: kitsuCharacter.Attributes.Name, Name: kitsuCharacter.Attributes.Name,
Image: kitsu.FixImageURL(kitsuCharacter.Attributes.Image.Original), Image: kitsu.FixImageURL(kitsuCharacter.Attributes.Image.Original),
Description: kitsuCharacter.Attributes.Description, Description: arn.FixAnimeDescription(kitsuCharacter.Attributes.Description),
} }
fmt.Printf("%s %s\n", character.ID, character.Name) fmt.Printf("%s %s\n", character.ID, character.Name)

View File

@ -15,6 +15,7 @@ import (
"github.com/animenotifier/notify.moe/pages/animelistitem" "github.com/animenotifier/notify.moe/pages/animelistitem"
"github.com/animenotifier/notify.moe/pages/apiview" "github.com/animenotifier/notify.moe/pages/apiview"
"github.com/animenotifier/notify.moe/pages/best" "github.com/animenotifier/notify.moe/pages/best"
"github.com/animenotifier/notify.moe/pages/character"
"github.com/animenotifier/notify.moe/pages/dashboard" "github.com/animenotifier/notify.moe/pages/dashboard"
"github.com/animenotifier/notify.moe/pages/editanime" "github.com/animenotifier/notify.moe/pages/editanime"
"github.com/animenotifier/notify.moe/pages/editor" "github.com/animenotifier/notify.moe/pages/editor"
@ -74,7 +75,8 @@ func configure(app *aero.Application) *aero.Application {
app.Ajax("/forum/:tag", forum.Get) app.Ajax("/forum/:tag", forum.Get)
app.Ajax("/thread/:id", threads.Get) app.Ajax("/thread/:id", threads.Get)
app.Ajax("/post/:id", posts.Get) app.Ajax("/post/:id", posts.Get)
app.Ajax("/tracks/:id", tracks.Get) app.Ajax("/track/:id", tracks.Get)
app.Ajax("/character/:id", character.Get)
app.Ajax("/new/thread", newthread.Get) app.Ajax("/new/thread", newthread.Get)
app.Ajax("/new/soundtrack", newsoundtrack.Get) app.Ajax("/new/soundtrack", newsoundtrack.Get)
app.Ajax("/settings", settings.Get) app.Ajax("/settings", settings.Get)

View File

@ -1,4 +1,4 @@
component Character(character *arn.Character) component Character(character *arn.Character)
a.character(href="#") a.character(href="/character/" + character.ID)
img.character-image.lazy(src="", data-src=character.Image, alt=character.Name, title=character.Name) img.character-image.lazy(src="", data-src=character.Image, alt=character.Name, title=character.Name)
span.character-name= character.Name span.character-name= character.Name

View File

@ -16,6 +16,7 @@
.character-image .character-image
border-radius 3px border-radius 3px
box-shadow shadow-medium
object-fit cover object-fit cover
.character-name .character-name

View File

@ -0,0 +1,21 @@
package character
import (
"net/http"
"github.com/aerogo/aero"
"github.com/animenotifier/arn"
"github.com/animenotifier/notify.moe/components"
)
// Get character.
func Get(ctx *aero.Context) string {
id := ctx.Get("id")
character, err := arn.GetCharacter(id)
if err != nil {
return ctx.Error(http.StatusNotFound, "Character not found", err)
}
return ctx.HTML(components.CharacterDetails(character))
}

View File

@ -0,0 +1,5 @@
component CharacterDetails(character *arn.Character)
h1= character.Name
p
img(src=character.Image, alt=character.Name)
p= character.Description

View File

@ -8,7 +8,7 @@ import (
"github.com/animenotifier/notify.moe/components" "github.com/animenotifier/notify.moe/components"
) )
// Get post. // Get track.
func Get(ctx *aero.Context) string { func Get(ctx *aero.Context) string {
id := ctx.Get("id") id := ctx.Get("id")
track, err := arn.GetSoundTrack(id) track, err := arn.GetSoundTrack(id)

View File

@ -75,8 +75,8 @@ var routeTests = map[string][]string{
"/search/Dragon Ball", "/search/Dragon Ball",
}, },
"/tracks/:id": []string{ "/track/:id": []string{
"/tracks/h0ac8sKkg", "/track/h0ac8sKkg",
}, },
// API // API