mirror of
https://github.com/ultrasn0w/huso.git
synced 2025-12-13 08:49:53 +01:00
Anime list fetching not broken but ugly insted ✔️
This commit is contained in:
4
go.mod
4
go.mod
@@ -25,6 +25,6 @@ require (
|
||||
github.com/xo/terminfo v0.0.0-20210125001918-ca9a967f8778 // indirect
|
||||
github.com/xujiajun/mmap-go v1.0.1 // indirect
|
||||
github.com/xujiajun/utils v0.0.0-20190123093513-8bf096c4f53b // indirect
|
||||
golang.org/x/crypto v0.0.0-20220817201139-bc19a97f63c8 // indirect
|
||||
golang.org/x/sys v0.0.0-20220818161305-2296e01440c6 // indirect
|
||||
golang.org/x/crypto v0.0.0-20220824171710-5757bc0c5503 // indirect
|
||||
golang.org/x/sys v0.0.0-20220823224334-20c2bfdbfe24 // indirect
|
||||
)
|
||||
|
||||
8
go.sum
8
go.sum
@@ -58,8 +58,8 @@ github.com/xujiajun/utils v0.0.0-20190123093513-8bf096c4f53b/go.mod h1:AZd87GYJl
|
||||
golang.org/x/crypto v0.0.0-20210421170649-83a5a9bb288b/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4=
|
||||
golang.org/x/crypto v0.0.0-20210513164829-c07d793c2f9a/go.mod h1:P+XmwS30IXTQdn5tA2iutPOUgjI07+tq3H3K9MVA1s8=
|
||||
golang.org/x/crypto v0.0.0-20220214200702-86341886e292/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
|
||||
golang.org/x/crypto v0.0.0-20220817201139-bc19a97f63c8 h1:GIAS/yBem/gq2MUqgNIzUHW7cJMmx3TGZOrnyYaNQ6c=
|
||||
golang.org/x/crypto v0.0.0-20220817201139-bc19a97f63c8/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
|
||||
golang.org/x/crypto v0.0.0-20220824171710-5757bc0c5503 h1:vJ2V3lFLg+bBhgroYuRfyN583UzVveQmIXjc8T/y3to=
|
||||
golang.org/x/crypto v0.0.0-20220824171710-5757bc0c5503/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
|
||||
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
|
||||
golang.org/x/net v0.0.0-20210510120150-4163338589ed/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
|
||||
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
|
||||
@@ -73,8 +73,8 @@ golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBc
|
||||
golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220227234510-4e6760a101f9/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220405210540-1e041c57c461/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220818161305-2296e01440c6 h1:Sx/u41w+OwrInGdEckYmEuU5gHoGSL4QbDz3S9s6j4U=
|
||||
golang.org/x/sys v0.0.0-20220818161305-2296e01440c6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220823224334-20c2bfdbfe24 h1:TyKJRhyo17yWxOMCTHKWrc5rddHORMlnZ/j57umaUd8=
|
||||
golang.org/x/sys v0.0.0-20220823224334-20c2bfdbfe24/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
|
||||
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
|
||||
4
huso.go
4
huso.go
@@ -20,7 +20,7 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
husoVersion = "1.7"
|
||||
husoVersion = "1.7.1"
|
||||
registerSecret = "綾波レイ"
|
||||
seasonStrJikan = "seasons/"
|
||||
userApiJikan = "users/"
|
||||
@@ -107,7 +107,7 @@ func main() {
|
||||
log.Fatal(err)
|
||||
}
|
||||
defer searchCache.Close()
|
||||
animeListCache, err = bigcache.NewBigCache(bigcache.DefaultConfig(42 * time.Minute))
|
||||
animeListCache, err = bigcache.NewBigCache(bigcache.DefaultConfig(24 * time.Minute))
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
@@ -82,10 +82,10 @@ func GetAnimeDetailData(animeId int64) (*Anime, []byte, error) {
|
||||
return &anime, data, err
|
||||
}
|
||||
|
||||
func GetUserAnimeListData(username, status string) (*AnimeListMal, []byte, error) {
|
||||
func GetUserAnimeListData(username, status string, refetch bool) (*AnimeListMal, []byte, error) {
|
||||
var list AnimeListMal
|
||||
data, err := animeListCache.Get(username + status)
|
||||
if err != nil {
|
||||
if refetch || err != nil {
|
||||
color.Infoln(username + "'s " + status + " abfragen...")
|
||||
//logOut.WriteLine("📄 " + username + "'s " + status + " abfragen...")
|
||||
data, err = GetDataMal(userApiMal + username + "/animelist?limit=1000&status=" + status + "&fields=list_status&nsfw=true")
|
||||
|
||||
22
ober.go
22
ober.go
@@ -692,18 +692,26 @@ func processUpdateReq(ctx *fasthttp.RequestCtx, update bool) {
|
||||
if update {
|
||||
// anime exitsts => save
|
||||
// get watch progress
|
||||
progress, updated, _, listState, _ := FetchProgress(anime.Anime, username)
|
||||
progress, updated, _, listState, _ := FetchProgress(anime.Anime, username, false)
|
||||
// anime is already completed big baka user
|
||||
if listState == malApiStatusC {
|
||||
ctx.WriteString("Du hast schon fertig geschaut bro")
|
||||
ctx.SetStatusCode(fasthttp.StatusConflict)
|
||||
return
|
||||
// One shot retry messy solution with refetch
|
||||
progress, updated, _, listState, _ = FetchProgress(anime.Anime, username, true)
|
||||
if listState == malApiStatusC {
|
||||
ctx.WriteString("Du hast schon fertig geschaut bro")
|
||||
ctx.SetStatusCode(fasthttp.StatusConflict)
|
||||
return
|
||||
}
|
||||
}
|
||||
// anime is already dropped big baka user
|
||||
if listState == malApiStatusD {
|
||||
ctx.WriteString("Du hast schon gedropped bro")
|
||||
ctx.SetStatusCode(fasthttp.StatusConflict)
|
||||
return
|
||||
// One shot retry messy solution with refetch
|
||||
progress, updated, _, listState, _ = FetchProgress(anime.Anime, username, true)
|
||||
if listState == malApiStatusD {
|
||||
ctx.WriteString("Du hast schon gedropped bro")
|
||||
ctx.SetStatusCode(fasthttp.StatusConflict)
|
||||
return
|
||||
}
|
||||
}
|
||||
animeData, err = AddUserToAnime(username, userId, anime.Anime, progress, updated)
|
||||
} else {
|
||||
|
||||
@@ -77,7 +77,7 @@ func Arbeit() {
|
||||
for _, a := range animesUsers {
|
||||
// iterate users
|
||||
for _, u := range a.Users {
|
||||
newProgress, updated, score, listState, err := FetchProgress(a.Anime, u.Username)
|
||||
newProgress, updated, score, listState, err := FetchProgress(a.Anime, u.Username, true)
|
||||
if err != nil {
|
||||
color.Errorln(err.Error())
|
||||
logOut.WriteError(err)
|
||||
|
||||
16
schaffer.go
16
schaffer.go
@@ -194,9 +194,9 @@ func SearchAppointments(animeId int64) ([]Appointment, error) {
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func FetchProgress(animeId int64, username string) (int, time.Time, int, string, error) {
|
||||
func FetchProgress(animeId int64, username string, refetch bool) (int, time.Time, int, string, error) {
|
||||
// check watching first
|
||||
newProgress, updated, score, err := FetchProgressOnState(animeId, username, malApiStatusW)
|
||||
newProgress, updated, score, err := FetchProgressOnState(animeId, username, malApiStatusW, refetch)
|
||||
if err != nil {
|
||||
return newProgress, updated, score, "", err
|
||||
}
|
||||
@@ -204,7 +204,7 @@ func FetchProgress(animeId int64, username string) (int, time.Time, int, string,
|
||||
return newProgress, updated, score, malApiStatusW, err
|
||||
}
|
||||
// check completed
|
||||
newProgress, updated, score, err = FetchProgressOnState(animeId, username, malApiStatusC)
|
||||
newProgress, updated, score, err = FetchProgressOnState(animeId, username, malApiStatusC, refetch)
|
||||
if err != nil {
|
||||
return newProgress, updated, score, "", err
|
||||
}
|
||||
@@ -212,7 +212,7 @@ func FetchProgress(animeId int64, username string) (int, time.Time, int, string,
|
||||
return newProgress, updated, score, malApiStatusC, err
|
||||
}
|
||||
// check on hold
|
||||
newProgress, updated, score, err = FetchProgressOnState(animeId, username, malApiStatusH)
|
||||
newProgress, updated, score, err = FetchProgressOnState(animeId, username, malApiStatusH, refetch)
|
||||
if err != nil {
|
||||
return newProgress, updated, score, "", err
|
||||
}
|
||||
@@ -220,7 +220,7 @@ func FetchProgress(animeId int64, username string) (int, time.Time, int, string,
|
||||
return newProgress, updated, score, malApiStatusH, err
|
||||
}
|
||||
// check dropped
|
||||
newProgress, updated, score, err = FetchProgressOnState(animeId, username, malApiStatusD)
|
||||
newProgress, updated, score, err = FetchProgressOnState(animeId, username, malApiStatusD, refetch)
|
||||
if err != nil {
|
||||
return newProgress, updated, score, "", err
|
||||
}
|
||||
@@ -231,8 +231,8 @@ func FetchProgress(animeId int64, username string) (int, time.Time, int, string,
|
||||
return 0, updated, 0, "", nil
|
||||
}
|
||||
|
||||
func FetchProgressOnState(animeId int64, username, malStatus string) (int, time.Time, int, error) {
|
||||
list, _, err := GetUserAnimeListData(username, malStatus)
|
||||
func FetchProgressOnState(animeId int64, username, malStatus string, refetch bool) (int, time.Time, int, error) {
|
||||
list, _, err := GetUserAnimeListData(username, malStatus, refetch)
|
||||
if err != nil {
|
||||
return 0, time.Time{}, 0, err
|
||||
}
|
||||
@@ -327,7 +327,7 @@ func BuildMovieCharts() ([]MovieChart, error) {
|
||||
|
||||
scoreSum := 0
|
||||
for _, u := range users {
|
||||
progress, _, score, err := FetchProgressOnState(c.Anime, u.Username, malApiStatusC)
|
||||
progress, _, score, err := FetchProgressOnState(c.Anime, u.Username, malApiStatusC, false)
|
||||
if err != nil {
|
||||
color.Errorln(err.Error())
|
||||
continue
|
||||
|
||||
Reference in New Issue
Block a user