Starting with a fresh database

This commit is contained in:
Eduard Urbach 2017-06-02 16:17:58 +02:00
parent a762b7bec1
commit 13c87d65d8
7 changed files with 170 additions and 117 deletions

View File

@ -1,46 +1,46 @@
package main
// package main
import (
"fmt"
"sort"
// import (
// "fmt"
// "sort"
"github.com/animenotifier/arn"
"github.com/fatih/color"
)
// "github.com/animenotifier/arn"
// "github.com/fatih/color"
// )
// AiringAnime ...
func AiringAnime() {
fmt.Println("Running background job: Airing Anime")
// // AiringAnime ...
// func AiringAnime() {
// fmt.Println("Running background job: Airing Anime")
animeList, err := arn.GetAiringAnime()
// animeList, err := arn.GetAiringAnime()
if err != nil {
color.Red("Failed fetching airing anime")
color.Red(err.Error())
return
}
// if err != nil {
// color.Red("Failed fetching airing anime")
// color.Red(err.Error())
// return
// }
sort.Sort(arn.AnimeByPopularity(animeList))
// sort.Sort(arn.AnimeByPopularity(animeList))
// Convert to small anime list
var animeListSmall []*arn.AnimeSmall
// // 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,
})
}
// 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,
})
// saveErr := arn.SetObject("Cache", "airingAnime", &arn.AiringAnimeCacheSmall{
// Anime: animeListSmall,
// })
if saveErr != nil {
color.Red("Error saving airing anime")
color.Red(saveErr.Error())
return
}
}
// if saveErr != nil {
// color.Red("Error saving airing anime")
// color.Red(saveErr.Error())
// return
// }
// }

View File

@ -0,0 +1,57 @@
package main
import (
"fmt"
"strconv"
"strings"
"github.com/animenotifier/arn"
"github.com/animenotifier/kitsu"
"github.com/fatih/color"
)
func main() {
color.Yellow("Syncing Anime")
// Get a stream of all anime
allAnime := kitsu.AllAnime()
// Iterate over the stream
for anime := range allAnime {
sync(anime)
}
}
func sync(data *kitsu.Anime) {
anime := arn.Anime{}
anime.ID, _ = strconv.Atoi(data.ID)
anime.Type = strings.ToLower(data.Attributes.ShowType)
anime.Title.Canonical = data.Attributes.CanonicalTitle
anime.Title.English = data.Attributes.Titles.En
anime.Title.Japanese = data.Attributes.Titles.JaJp
anime.Title.Romaji = data.Attributes.Titles.EnJp
anime.Title.Synonyms = data.Attributes.AbbreviatedTitles
anime.Image = data.Attributes.PosterImage.Original
anime.Summary = arn.FixAnimeDescription(data.Attributes.Synopsis)
if data.Attributes.YoutubeVideoID != "" {
anime.Trailers = append(anime.Trailers, &arn.AnimeTrailer{
Service: "Youtube",
VideoID: data.Attributes.YoutubeVideoID,
})
}
err := anime.Save()
status := ""
if err == nil {
status = color.GreenString("✔")
} else {
status = color.RedString("✘")
}
fmt.Println(status, anime.ID, anime.Title.Canonical)
}

View File

@ -7,6 +7,7 @@ import (
"github.com/animenotifier/notify.moe/components"
"github.com/animenotifier/notify.moe/pages/airing"
"github.com/animenotifier/notify.moe/pages/anime"
"github.com/animenotifier/notify.moe/pages/dashboard"
"github.com/animenotifier/notify.moe/pages/forum"
"github.com/animenotifier/notify.moe/pages/forums"
"github.com/animenotifier/notify.moe/pages/genre"
@ -33,9 +34,7 @@ func main() {
}
// Ajax routes
app.Ajax("/", func(ctx *aero.Context) string {
return ctx.HTML("ARN 4.0 is currently under construction.<br><a href='https://paypal.me/blitzprog' target='_blank' rel='noopener'>Support the development</a>")
})
app.Ajax("/", dashboard.Get)
app.Ajax("/anime", search.Get)
app.Ajax("/anime/:id", anime.Get)
app.Ajax("/genres", genres.Get)

View File

@ -2,18 +2,17 @@ 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)
// airingAnimeCache := new(arn.AiringAnimeCache)
// err := arn.GetObject("Cache", "airingAnime", airingAnimeCache)
if err != nil {
return ctx.Error(500, "Couldn't fetch airing anime", err)
}
// if err != nil {
// return ctx.Error(500, "Couldn't fetch airing anime", err)
// }
return ctx.HTML(components.Airing(airingAnimeCache.Anime))
// return ctx.HTML(components.Airing(airingAnimeCache.Anime))
return ctx.HTML("Coming soon.")
}

View File

@ -7,25 +7,25 @@ component Anime(anime *arn.Anime)
.space
.anime-info
h2.anime-title(title=anime.Type)= anime.Title.Romaji
h2.anime-title(title=anime.Type)= anime.Title.Canonical
//- if user && user.titleLanguage === "japanese"
//- span.second-title(title=anime.Title.English !== anime.Title.Romaji ? anime.Title.English : null)= anime.Title.Romaji
//- else
if anime.Title.Japanese != anime.Title.Romaji
if anime.Title.Japanese != anime.Title.Canonical
a.anime-alternative-title(href="http://jisho.org/search/" + anime.Title.Japanese, target="_blank", title="Look up reading on jisho.org", rel="nofollow")= anime.Title.Japanese
//- h3.anime-section-name.anime-summary-header Summary
p.anime-summary= arn.FixAnimeDescription(anime.Description)
p.anime-summary= anime.Summary
if anime.YoutubeID != ""
if len(anime.Trailers) > 0 && anime.Trailers[0].Service == "Youtube" && anime.Trailers[0].VideoID != ""
h3.anime-section-name Video
.anime-trailer.video-container
iframe.video(src="https://www.youtube.com/embed/" + anime.YoutubeID + "?showinfo=0", allowfullscreen="allowfullscreen")
iframe.video(src="https://www.youtube.com/embed/" + anime.Trailers[0].VideoID + "?showinfo=0", allowfullscreen="allowfullscreen")
if anime.Tracks != nil && anime.Tracks.Opening != nil
h3.anime-section-name Tracks
iframe.anime-track(src="https://w.soundcloud.com/player/?url=" + anime.Tracks.Opening.URI + "?auto_play=false&hide_related=true&show_comments=true&show_user=true&show_reposts=false&visual=true")
//- if anime.Tracks != nil && anime.Tracks.Opening != nil
//- h3.anime-section-name Tracks
//- iframe.anime-track(src="https://w.soundcloud.com/player/?url=" + anime.Tracks.Opening.URI + "?auto_play=false&hide_related=true&show_comments=true&show_user=true&show_reposts=false&visual=true")
//- if user && friendsWatching && friendsWatching.length > 0
//- include ../messages/avatar.pug
@ -35,30 +35,30 @@ component Anime(anime *arn.Anime)
//- each watcher in friendsWatching
//- +avatar(watcher)
if len(anime.Relations) > 0
h3.anime-section-name Relations
.relations
each relation in anime.Relations
a.relation.ajax(href="/anime/" + toString(relation.ID), title=relation.Anime().Title.Romaji)
img.anime-image.relation-image(src=relation.Anime().Image, alt=relation.Anime().Title.Romaji)
.relation-type= arn.Capitalize(relation.Type)
//- if len(anime.Relations) > 0
//- h3.anime-section-name Relations
//- .relations
//- each relation in anime.Relations
//- a.relation.ajax(href="/anime/" + toString(relation.ID), title=relation.Anime().Title.Romaji)
//- img.anime-image.relation-image(src=relation.Anime().Image, alt=relation.Anime().Title.Romaji)
//- .relation-type= arn.Capitalize(relation.Type)
if len(anime.Genres) > 0
h3.anime-section-name Genres
.light-button-group
each genre in anime.Genres
if genre != ""
a.light-button.ajax(href="/genres/" + arn.GetGenreIDByName(genre))
Icon(arn.GetGenreIcon(genre))
span= genre
//- if len(anime.Genres) > 0
//- h3.anime-section-name Genres
//- .light-button-group
//- each genre in anime.Genres
//- if genre != ""
//- a.light-button.ajax(href="/genres/" + arn.GetGenreIDByName(genre))
//- Icon(arn.GetGenreIcon(genre))
//- span= genre
if len(anime.Studios) > 0
h3.anime-section-name Studios
.light-button-group
each studio in anime.Studios
a.light-button(href="https://anilist.co/studio/" + toString(studio.ID), target="_blank")
Icon("building")
span= studio.Name
//- if len(anime.Studios) > 0
//- h3.anime-section-name Studios
//- .light-button-group
//- each studio in anime.Studios
//- a.light-button(href="https://anilist.co/studio/" + toString(studio.ID), target="_blank")
//- Icon("building")
//- span= studio.Name
//- //-if crunchy
//- //- h3.anime-section-name Episodes
@ -106,18 +106,18 @@ component Anime(anime *arn.Anime)
//- if providers.Nyaa && providers.Nyaa.episodes !== undefined
//- span(class=providers.Nyaa.episodes === 0 ? "entry-error" : "entry-ok")= providers.Nyaa.episodes + " eps"
h3.anime-section-name Links
.light-button-group
if anime.Links != nil
each link in anime.Links
a.light-button(href=link.URL, target="_blank")
Icon("external-link")
span= link.Title
//- h3.anime-section-name Links
//- .light-button-group
//- if anime.Links != nil
//- each link in anime.Links
//- a.light-button(href=link.URL, target="_blank")
//- Icon("external-link")
//- span= link.Title
if anime.CreatedBy == ""
a.light-button(href="https://anilist.co/anime/" + toString(anime.ID), target="_blank")
Icon("external-link")
span AniList
//- if anime.CreatedBy == ""
//- a.light-button(href="https://anilist.co/anime/" + toString(anime.ID), target="_blank")
//- Icon("external-link")
//- span AniList
//- if providers.HummingBird
//- a.light-button(href="https://hummingbird.me/anime/" + providers.HummingBird.providerId, target="_blank") HummingBird
@ -129,7 +129,7 @@ component Anime(anime *arn.Anime)
//- a.light-button(href="http://www.anime-planet.com/anime/" + providers.AnimePlanet.providerId, target="_blank") AnimePlanet
.sources
p Powered by Anilist.
p Powered by Kitsu.
//- if descriptionSource
//- span= " Summary by " + summarySource + "."
//- //-

View File

@ -2,25 +2,24 @@ package dashboard
import (
"github.com/aerogo/aero"
"github.com/animenotifier/arn"
"github.com/animenotifier/notify.moe/components"
)
const maxPosts = 5
// Get ...
func Get(ctx *aero.Context) string {
posts, err := arn.GetPosts()
// posts, err := arn.GetPosts()
if err != nil {
return ctx.Error(500, "Error fetching posts", err)
}
arn.SortPostsLatestFirst(posts)
if len(posts) > maxPosts {
posts = posts[:maxPosts]
}
return ctx.HTML(components.Dashboard(posts))
// if err != nil {
// return ctx.Error(500, "Error fetching posts", err)
// }
// arn.SortPostsLatestFirst(posts)
// if len(posts) > maxPosts {
// posts = posts[:maxPosts]
// }
// return ctx.HTML(components.Dashboard(posts))
return ctx.HTML("ARN 4.0 is currently under construction.<br><a href='https://paypal.me/blitzprog' target='_blank' rel='noopener'>Support the development</a>")
}

View File

@ -2,29 +2,28 @@ package search
import (
"github.com/aerogo/aero"
"github.com/animenotifier/arn"
"github.com/animenotifier/notify.moe/components"
)
// Get ...
func Get(ctx *aero.Context) string {
titleCount := 0
animeCount := 0
// titleCount := 0
// animeCount := 0
// let info: any = await bluebird.props({
// popular: arn.db.get('Cache', 'popularAnime'),
// stats: arn.db.get('Cache', 'animeStats')
// })
// // let info: any = await bluebird.props({
// // popular: arn.db.get('Cache', 'popularAnime'),
// // stats: arn.db.get('Cache', 'animeStats')
// // })
// return response.render({
// user,
// popularAnime: info.popular.anime,
// animeCount: info.stats.animeCount,
// titleCount: info.stats.titleCount,
// anime: null
// })
// // return response.render({
// // user,
// // popularAnime: info.popular.anime,
// // animeCount: info.stats.animeCount,
// // titleCount: info.stats.titleCount,
// // anime: null
// // })
popular, _ := arn.GetPopularCache()
// popular, _ := arn.GetPopularCache()
return ctx.HTML(components.Search(popular.Anime, titleCount, animeCount))
// return ctx.HTML(components.Search(popular.Anime, titleCount, animeCount))
return ctx.HTML("Coming soon.")
}