Added API for popular anime titles
This commit is contained in:
parent
a3b553d8de
commit
0d0ae75bd4
@ -33,6 +33,7 @@ import (
|
|||||||
"github.com/animenotifier/notify.moe/pages/newthread"
|
"github.com/animenotifier/notify.moe/pages/newthread"
|
||||||
"github.com/animenotifier/notify.moe/pages/notifications"
|
"github.com/animenotifier/notify.moe/pages/notifications"
|
||||||
"github.com/animenotifier/notify.moe/pages/paypal"
|
"github.com/animenotifier/notify.moe/pages/paypal"
|
||||||
|
"github.com/animenotifier/notify.moe/pages/popular"
|
||||||
"github.com/animenotifier/notify.moe/pages/posts"
|
"github.com/animenotifier/notify.moe/pages/posts"
|
||||||
"github.com/animenotifier/notify.moe/pages/profile"
|
"github.com/animenotifier/notify.moe/pages/profile"
|
||||||
"github.com/animenotifier/notify.moe/pages/search"
|
"github.com/animenotifier/notify.moe/pages/search"
|
||||||
@ -175,6 +176,7 @@ func Configure(app *aero.Application) {
|
|||||||
|
|
||||||
// API
|
// API
|
||||||
app.Get("/api/me", me.Get)
|
app.Get("/api/me", me.Get)
|
||||||
|
app.Get("/api/popular/anime/titles/:count", popular.AnimeTitles)
|
||||||
app.Get("/api/test/notification", notifications.Test)
|
app.Get("/api/test/notification", notifications.Test)
|
||||||
|
|
||||||
// PayPal
|
// PayPal
|
||||||
|
36
pages/popular/anime.go
Normal file
36
pages/popular/anime.go
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
package popular
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net/http"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/aerogo/aero"
|
||||||
|
"github.com/animenotifier/arn"
|
||||||
|
)
|
||||||
|
|
||||||
|
// AnimeTitles returns a list of the 500 most popular anime titles.
|
||||||
|
func AnimeTitles(ctx *aero.Context) string {
|
||||||
|
maxLength, err := ctx.GetInt("count")
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return ctx.Error(http.StatusBadRequest, "Invalid value for count parameter", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
popularAnimeTitles := []string{}
|
||||||
|
popularAnime := arn.AllAnime()
|
||||||
|
arn.SortAnimeByPopularity(popularAnime)
|
||||||
|
|
||||||
|
if len(popularAnime) > maxLength {
|
||||||
|
popularAnime = popularAnime[:maxLength]
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, anime := range popularAnime {
|
||||||
|
popularAnimeTitles = append(popularAnimeTitles, strings.ToLower(anime.Title.Canonical))
|
||||||
|
|
||||||
|
if arn.ContainsUnicodeLetters(anime.Title.Japanese) {
|
||||||
|
popularAnimeTitles = append(popularAnimeTitles, anime.Title.Japanese)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return ctx.JSON(popularAnimeTitles)
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user