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
import (
"fmt"
"time"
"github.com/animenotifier/arn"
"github.com/fatih/color"
)
func main() {
anime, _ := arn.GetAnime("6887")
err := anime.RefreshAnimeCharacters()
arn.PanicOnError(err)
color.Yellow("Refreshing anime characters...")
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.")
}

View File

@ -18,7 +18,7 @@ func main() {
ID: kitsuCharacter.ID,
Name: kitsuCharacter.Attributes.Name,
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)

View File

@ -15,6 +15,7 @@ import (
"github.com/animenotifier/notify.moe/pages/animelistitem"
"github.com/animenotifier/notify.moe/pages/apiview"
"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/editanime"
"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("/thread/:id", threads.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/soundtrack", newsoundtrack.Get)
app.Ajax("/settings", settings.Get)

View File

@ -1,4 +1,4 @@
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)
span.character-name= character.Name

View File

@ -16,6 +16,7 @@
.character-image
border-radius 3px
box-shadow shadow-medium
object-fit cover
.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"
)
// Get post.
// Get track.
func Get(ctx *aero.Context) string {
id := ctx.Get("id")
track, err := arn.GetSoundTrack(id)

View File

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