LastSeason

This commit is contained in:
daru
2022-07-01 18:43:30 +02:00
parent be04fb92e5
commit d87b658837
5 changed files with 51 additions and 0 deletions

View File

@@ -44,6 +44,7 @@ _X-HUSO-AUTH_ -> _secret_ des users
| GET | /api/season | Aktuelle Season holen | []Anime JSON | | | |
| GET | /api/nextseason | Nächste Season holen | []Anime JSON | | | |
| GET | /api/nextnextseason | Übernächste Season holen | []Anime JSON | | | |
| GET | /api/lastseason | Letzte Season holen | []Anime JSON | | | |
| GET | /api/anime/{id} | Einzelnen Anime holen | Anime JSON | {id} = MAL Anime id | | |
| GET | /api/animesearch | Anime auf MAL suchen | []Anime JSON | Query parameter {q} = Suchtext | | |

View File

@@ -274,3 +274,19 @@ func GetNextNextSeasonString() string {
return fmt.Sprintf("%04d", now.Year())
}
}
func GetLastSeasonString() string {
var now = time.Now()
switch now.Month() {
case time.January, time.February, time.March:
return fmt.Sprintf("%04d/fall", now.Year()-1)
case time.April, time.May, time.June:
return fmt.Sprintf("%04d/winter", now.Year())
case time.July, time.August, time.September:
return fmt.Sprintf("%04d/spring", now.Year())
case time.October, time.November, time.December:
return fmt.Sprintf("%04d/summer", now.Year())
default:
return fmt.Sprintf("%04d", now.Year())
}
}

18
ober.go
View File

@@ -20,6 +20,7 @@ func RunWebserv() {
r.GET("/api/season", Headers(Season))
r.GET("/api/nextseason", Headers(SeasonNext))
r.GET("/api/nextnextseason", Headers(SeasonNextNext))
r.GET("/api/lastseason", Headers(SeasonLast))
r.GET("/api/auth/{user}", Headers(AuthTest))
r.GET("/api/anime/{id}", Headers(AnimeGet))
r.GET("/api/animesearch", Headers(AnimeSearchGet))
@@ -128,6 +129,23 @@ func SeasonNextNext(ctx *fasthttp.RequestCtx) {
ctx.SetStatusCode(fasthttp.StatusOK)
}
func SeasonLast(ctx *fasthttp.RequestCtx) {
data, err := seasoncache.Get(GetLastSeasonString())
if err != nil {
addErrorToCtx(ctx, err)
return
}
err = writeResponseBody(ctx, data)
if err != nil {
addErrorToCtx(ctx, err)
return
}
ctx.SetContentType("application/json; charset=utf-8")
ctx.SetStatusCode(fasthttp.StatusOK)
}
func AnimeGet(ctx *fasthttp.RequestCtx) {
idVal := ctx.UserValue("id")
if idVal == nil {

View File

@@ -171,6 +171,13 @@ func LangeArbeit() {
logOut.WriteError(err)
}
// last season data
err = refreshSeason(GetLastSeasonString())
if err != nil {
color.Errorln(err.Error())
logOut.WriteError(err)
}
// refresh anime cache with watched
count := 0
animesUsers, err := ReadAnimeUsers()

View File

@@ -151,6 +151,15 @@ func SearchSeasons(animeId int64) (*Anime, error) {
return &a, err
}
}
season, err = GetSeasonCache(GetLastSeasonString())
if err != nil {
return nil, err
}
for _, a := range season {
if a.Anime == animeId {
return &a, err
}
}
return nil, errors.New("anime not found")
}