Use new character structure
This commit is contained in:
parent
a1cfe624ae
commit
fd6ab8eb02
@ -2,6 +2,8 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"path"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/animenotifier/arn"
|
"github.com/animenotifier/arn"
|
||||||
@ -18,10 +20,27 @@ func main() {
|
|||||||
for kitsuCharacter := range kitsuCharacters {
|
for kitsuCharacter := range kitsuCharacters {
|
||||||
character := &arn.Character{
|
character := &arn.Character{
|
||||||
ID: kitsuCharacter.ID,
|
ID: kitsuCharacter.ID,
|
||||||
Name: kitsuCharacter.Attributes.Name,
|
Name: arn.CharacterName{
|
||||||
Image: kitsu.FixImageURL(kitsuCharacter.Attributes.Image.Original),
|
Canonical: kitsuCharacter.Attributes.Name,
|
||||||
|
},
|
||||||
|
Image: arn.CharacterImage{
|
||||||
|
Extension: path.Ext(kitsu.FixImageURL(kitsuCharacter.Attributes.Image.Original)),
|
||||||
|
},
|
||||||
Description: kitsuCharacter.Attributes.Description,
|
Description: kitsuCharacter.Attributes.Description,
|
||||||
Attributes: []*arn.CharacterAttribute{},
|
Attributes: []*arn.CharacterAttribute{},
|
||||||
|
Mappings: []*arn.Mapping{
|
||||||
|
&arn.Mapping{
|
||||||
|
Service: "kitsu/character",
|
||||||
|
ServiceID: kitsuCharacter.ID,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
if kitsuCharacter.Attributes.MalID != 0 {
|
||||||
|
character.Mappings = append(character.Mappings, &arn.Mapping{
|
||||||
|
Service: "myanimelist/character",
|
||||||
|
ServiceID: strconv.Itoa(kitsuCharacter.Attributes.MalID),
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// We use markdown, so replace <br/> with two line breaks.
|
// We use markdown, so replace <br/> with two line breaks.
|
||||||
|
@ -1,52 +0,0 @@
|
|||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/animenotifier/jikan"
|
|
||||||
|
|
||||||
"github.com/animenotifier/arn"
|
|
||||||
"github.com/fatih/color"
|
|
||||||
)
|
|
||||||
|
|
||||||
var jikanDB = arn.Node.Namespace("jikan")
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
color.Yellow("Syncing with Jikan API")
|
|
||||||
defer arn.Node.Close()
|
|
||||||
|
|
||||||
count := 0
|
|
||||||
|
|
||||||
for anime := range arn.StreamAnime() {
|
|
||||||
malID := anime.GetMapping("myanimelist/anime")
|
|
||||||
|
|
||||||
if malID != "" {
|
|
||||||
sync(anime, malID)
|
|
||||||
count++
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
color.Green("Finished syncing %d anime.", count)
|
|
||||||
|
|
||||||
// Give OS some time to write buffers, just to be safe
|
|
||||||
time.Sleep(10 * time.Second)
|
|
||||||
}
|
|
||||||
|
|
||||||
func sync(anime *arn.Anime, malID string) {
|
|
||||||
fmt.Printf("%s %s (MAL: %s)\n", anime.ID, anime.Title.Canonical, malID)
|
|
||||||
|
|
||||||
if jikanDB.Exists("Anime", malID) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
time.Sleep(2 * time.Second)
|
|
||||||
jikanAnime, err := jikan.GetAnime(malID)
|
|
||||||
|
|
||||||
if err == nil {
|
|
||||||
jikanDB.Set("Anime", malID, jikanAnime)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
fmt.Printf("Error fetching %s: %v\n", malID, err)
|
|
||||||
}
|
|
@ -1,63 +0,0 @@
|
|||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/animenotifier/jikan"
|
|
||||||
|
|
||||||
"github.com/animenotifier/arn"
|
|
||||||
"github.com/fatih/color"
|
|
||||||
)
|
|
||||||
|
|
||||||
var jikanDB = arn.Node.Namespace("jikan")
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
color.Yellow("Syncing characters with Jikan API")
|
|
||||||
defer arn.Node.Close()
|
|
||||||
|
|
||||||
allAnime := jikanDB.All("Anime")
|
|
||||||
|
|
||||||
count := 0
|
|
||||||
|
|
||||||
for animeObj := range allAnime {
|
|
||||||
anime := animeObj.(*jikan.Anime)
|
|
||||||
|
|
||||||
if len(anime.Character) == 0 {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
fmt.Println(anime.Title)
|
|
||||||
|
|
||||||
for _, character := range anime.Character {
|
|
||||||
characterID := jikan.GetCharacterIDFromURL(character.URL)
|
|
||||||
|
|
||||||
if characterID == "" {
|
|
||||||
fmt.Println("Invalid character ID")
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
fetchCharacter(characterID)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
color.Green("Finished syncing %d characters.", count)
|
|
||||||
}
|
|
||||||
|
|
||||||
func fetchCharacter(malCharacterID string) {
|
|
||||||
fmt.Printf("Fetching character ID %s\n", malCharacterID)
|
|
||||||
|
|
||||||
if jikanDB.Exists("Character", malCharacterID) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
time.Sleep(500 * time.Millisecond)
|
|
||||||
character, err := jikan.GetCharacter(malCharacterID)
|
|
||||||
|
|
||||||
if err == nil {
|
|
||||||
jikanDB.Set("Character", malCharacterID, character)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
fmt.Printf("Error fetching %s: %v\n", malCharacterID, err)
|
|
||||||
}
|
|
@ -1,7 +1,7 @@
|
|||||||
component Character(character *arn.Character)
|
component Character(character *arn.Character)
|
||||||
a.character(href="/character/" + character.ID)
|
a.character(href="/character/" + character.ID)
|
||||||
img.character-image.lazy(data-src=character.Image, alt=character.Name, title=character.Name)
|
img.character-image.lazy(data-src=character.ImageLink("medium"), alt=character.Name, title=character.Name)
|
||||||
|
|
||||||
component CharacterSmall(character *arn.Character)
|
component CharacterSmall(character *arn.Character)
|
||||||
a.character(href="/character/" + character.ID)
|
a.character(href="/character/" + character.ID)
|
||||||
img.character-image.character-image-small.lazy(data-src=character.Image, alt=character.Name, title=character.Name)
|
img.character-image.character-image-small.lazy(data-src=character.ImageLink("small"), alt=character.Name, title=character.Name)
|
@ -49,8 +49,8 @@ func Get(ctx *aero.Context) string {
|
|||||||
|
|
||||||
ctx.Data = &arn.OpenGraph{
|
ctx.Data = &arn.OpenGraph{
|
||||||
Tags: map[string]string{
|
Tags: map[string]string{
|
||||||
"og:title": character.Name,
|
"og:title": character.Name.Canonical,
|
||||||
"og:image": "https:" + character.Image,
|
"og:image": "https:" + character.ImageLink("large"),
|
||||||
"og:url": "https://" + ctx.App.Config.Domain + character.Link(),
|
"og:url": "https://" + ctx.App.Config.Domain + character.Link(),
|
||||||
"og:site_name": "notify.moe",
|
"og:site_name": "notify.moe",
|
||||||
"og:description": description,
|
"og:description": description,
|
||||||
@ -61,7 +61,7 @@ func Get(ctx *aero.Context) string {
|
|||||||
},
|
},
|
||||||
Meta: map[string]string{
|
Meta: map[string]string{
|
||||||
"description": description,
|
"description": description,
|
||||||
"keywords": character.Name + ",anime,character",
|
"keywords": character.Name.Canonical + ",anime,character",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,11 +3,16 @@ component CharacterDetails(character *arn.Character, characterAnime []*arn.Anime
|
|||||||
.character-left-column
|
.character-left-column
|
||||||
.character-header
|
.character-header
|
||||||
.character-image-container
|
.character-image-container
|
||||||
img.character-image-fullsize(src=character.Image, alt=character.Name)
|
img.character-image-fullsize(src=character.ImageLink("large"), alt=character.Name.Canonical)
|
||||||
.character-description-container
|
.character-description-container
|
||||||
h1.character-name= character.Name
|
h1.character-name= character.Name.Canonical
|
||||||
|
|
||||||
.anime-alternative-title
|
.anime-alternative-title
|
||||||
|
if character.Name.Japanese != ""
|
||||||
|
Japanese(character.Name.Japanese)
|
||||||
|
else
|
||||||
Japanese("日本語の名前無し")
|
Japanese("日本語の名前無し")
|
||||||
|
|
||||||
.character-description!= markdown.Render(character.Description)
|
.character-description!= markdown.Render(character.Description)
|
||||||
|
|
||||||
h3 Anime
|
h3 Anime
|
||||||
|
@ -29,7 +29,7 @@ func Edit(ctx *aero.Context) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if quote.Character() != nil {
|
if quote.Character() != nil {
|
||||||
ctx.Data.(*arn.OpenGraph).Tags["og:image"] = quote.Character().Image
|
ctx.Data.(*arn.OpenGraph).Tags["og:image"] = quote.Character().ImageLink("large")
|
||||||
}
|
}
|
||||||
|
|
||||||
return ctx.HTML(components.QuoteTabs(quote, user) + editform.Render(quote, "Edit quote", user))
|
return ctx.HTML(components.QuoteTabs(quote, user) + editform.Render(quote, "Edit quote", user))
|
||||||
|
@ -32,8 +32,8 @@ func Get(ctx *aero.Context) string {
|
|||||||
character, _ := arn.GetCharacter(quote.CharacterID)
|
character, _ := arn.GetCharacter(quote.CharacterID)
|
||||||
|
|
||||||
if character != nil {
|
if character != nil {
|
||||||
openGraph.Tags["og:title"] = character.Name + "'s quote"
|
openGraph.Tags["og:title"] = character.Name.Canonical + "'s quote"
|
||||||
openGraph.Tags["og:image"] = "https:" + character.Image
|
openGraph.Tags["og:image"] = "https:" + character.ImageLink("large")
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx.Data = openGraph
|
ctx.Data = openGraph
|
||||||
|
@ -157,7 +157,7 @@ func RenderField(b *bytes.Buffer, v *reflect.Value, field reflect.StructField, i
|
|||||||
character, err := arn.GetCharacter(characterID)
|
character, err := arn.GetCharacter(characterID)
|
||||||
|
|
||||||
if err == nil {
|
if err == nil {
|
||||||
b.WriteString(components.EditFormImagePreview(character.Link(), character.Image, false))
|
b.WriteString(components.EditFormImagePreview(character.Link(), character.ImageLink("small"), false))
|
||||||
}
|
}
|
||||||
|
|
||||||
case "":
|
case "":
|
||||||
|
Loading…
Reference in New Issue
Block a user