From 13c87d65d8d3a897588d35f5cec1e311cd06c054 Mon Sep 17 00:00:00 2001 From: Eduard Urbach Date: Fri, 2 Jun 2017 16:17:58 +0200 Subject: [PATCH] Starting with a fresh database --- jobs/airing-anime.go | 72 +++++++++++++++--------------- jobs/sync-anime/sync-anime.go | 57 ++++++++++++++++++++++++ main.go | 5 +-- pages/airing/airing.go | 15 +++---- pages/anime/anime.pixy | 84 +++++++++++++++++------------------ pages/dashboard/dashboard.go | 21 +++++---- pages/search/search.go | 33 +++++++------- 7 files changed, 170 insertions(+), 117 deletions(-) create mode 100644 jobs/sync-anime/sync-anime.go diff --git a/jobs/airing-anime.go b/jobs/airing-anime.go index 96c96c89..3fe5eb6c 100644 --- a/jobs/airing-anime.go +++ b/jobs/airing-anime.go @@ -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 +// } +// } diff --git a/jobs/sync-anime/sync-anime.go b/jobs/sync-anime/sync-anime.go new file mode 100644 index 00000000..1290898b --- /dev/null +++ b/jobs/sync-anime/sync-anime.go @@ -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) + +} diff --git a/main.go b/main.go index 25461bc4..e1da257d 100644 --- a/main.go +++ b/main.go @@ -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.
Support the development") - }) + app.Ajax("/", dashboard.Get) app.Ajax("/anime", search.Get) app.Ajax("/anime/:id", anime.Get) app.Ajax("/genres", genres.Get) diff --git a/pages/airing/airing.go b/pages/airing/airing.go index 190cb41e..e34abfcf 100644 --- a/pages/airing/airing.go +++ b/pages/airing/airing.go @@ -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.") } diff --git a/pages/anime/anime.pixy b/pages/anime/anime.pixy index bc4d6c80..911df6a5 100644 --- a/pages/anime/anime.pixy +++ b/pages/anime/anime.pixy @@ -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 + "." //- //- diff --git a/pages/dashboard/dashboard.go b/pages/dashboard/dashboard.go index edef16f9..0a051020 100644 --- a/pages/dashboard/dashboard.go +++ b/pages/dashboard/dashboard.go @@ -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) - } + // if err != nil { + // return ctx.Error(500, "Error fetching posts", err) + // } - arn.SortPostsLatestFirst(posts) + // arn.SortPostsLatestFirst(posts) - if len(posts) > maxPosts { - posts = posts[:maxPosts] - } + // if len(posts) > maxPosts { + // posts = posts[:maxPosts] + // } - return ctx.HTML(components.Dashboard(posts)) + // return ctx.HTML(components.Dashboard(posts)) + return ctx.HTML("ARN 4.0 is currently under construction.
Support the development") } diff --git a/pages/search/search.go b/pages/search/search.go index e42d9746..f9a15766 100644 --- a/pages/search/search.go +++ b/pages/search/search.go @@ -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.") }