From fd84193d9d96a6eb499a863ff8f6f627face7483 Mon Sep 17 00:00:00 2001 From: daru Date: Fri, 1 Jul 2022 17:47:08 +0200 Subject: [PATCH] the big talk --- huso.go | 2 +- knecht.go | 2 ++ praktikant.go | 14 +++++++++++--- schaffer.go | 16 ++++++++-------- 4 files changed, 22 insertions(+), 12 deletions(-) diff --git a/huso.go b/huso.go index b803bd1..a664151 100644 --- a/huso.go +++ b/huso.go @@ -74,7 +74,7 @@ func main() { color.Notice.Printf("huso %s built on %s with %s\n", husoVersion, buildTime, runtime.Version()) logOut.WriteLine(fmt.Sprintf("🎉 huso %s built on %s with %s", husoVersion, buildTime, runtime.Version())) - jikanLimiter = rate.NewLimiter(rate.Every(time.Second), 1) + jikanLimiter = rate.NewLimiter(rate.Every(time.Second+(time.Millisecond*420)), 1) // cache init var err error diff --git a/knecht.go b/knecht.go index 250c5ba..c4bae8f 100644 --- a/knecht.go +++ b/knecht.go @@ -75,6 +75,8 @@ func GetUserAnimeListData(username, status string) (*AnimeListMal, []byte, error var list AnimeListMal data, err := animeListCache.Get(username + status) if 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") if err != nil { return nil, nil, err diff --git a/praktikant.go b/praktikant.go index e2cb05b..0586e6b 100644 --- a/praktikant.go +++ b/praktikant.go @@ -55,6 +55,9 @@ func Arbeit() { } return } + color.Infoln("Animelisten abfragen...") + logOut.WriteLine("📜 Animelisten abfragen...") + count := 0 // iterate anime for _, a := range animesUsers { // iterate users @@ -68,40 +71,45 @@ func Arbeit() { // check if user set anime as completed if listState == malApiStatusC { color.Infof("%s finished %d scored %d\n", u.Username, a.Anime, score) - logOut.WriteLine(fmt.Sprintf("📜 %s finished %d scored %d !", u.Username, a.Anime, score)) + logOut.WriteLine(fmt.Sprintf("📝 %s finished %d scored %d !", u.Username, a.Anime, score)) // delete user from anime _, err = DeleteUserFromAnime(u.Username, u.MalID, a.Anime) if err != nil { color.Errorln(err.Error()) logOut.WriteError(err) } + count++ continue } // check if user set anime as dropped if listState == malApiStatusD { color.Infof("%s dropped %d\n", u.Username, a.Anime) - logOut.WriteLine(fmt.Sprintf("📜 %s dropped %d !", u.Username, a.Anime)) + logOut.WriteLine(fmt.Sprintf("📝 %s dropped %d !", u.Username, a.Anime)) // delete user from anime _, err = DeleteUserFromAnime(u.Username, u.MalID, a.Anime) if err != nil { color.Errorln(err.Error()) logOut.WriteError(err) } + count++ continue } if newProgress == u.Progress { continue } color.Infof("%s progress von %d: %d -> %d\n", u.Username, a.Anime, u.Progress, newProgress) - logOut.WriteLine(fmt.Sprintf("📜 %s progress von %d: %d -> %d", u.Username, a.Anime, u.Progress, newProgress)) + logOut.WriteLine(fmt.Sprintf("📝 %s progress von %d: %d -> %d", u.Username, a.Anime, u.Progress, newProgress)) // update db err = UpdateUserAnimeProgress(a.Anime, u.MalID, newProgress, updated) if err != nil { color.Errorln(err.Error()) logOut.WriteError(err) } + count++ } } + color.Infof("%d Sachen aktualisiert\n", count) + logOut.WriteLine(fmt.Sprintf("📜 %d Sachen aktualisiert", count)) } func BissleArbeiten() { diff --git a/schaffer.go b/schaffer.go index e543105..8b79191 100644 --- a/schaffer.go +++ b/schaffer.go @@ -191,14 +191,6 @@ func FetchProgress(animeId int64, username string) (int, time.Time, int, string, if newProgress != -1 { return newProgress, updated, score, malApiStatusW, err } - // check on hold - newProgress, updated, score, err = FetchProgressOnState(animeId, username, malApiStatusH) - if err != nil { - return newProgress, updated, score, "", err - } - if newProgress != -1 { - return newProgress, updated, score, malApiStatusH, err - } // check completed newProgress, updated, score, err = FetchProgressOnState(animeId, username, malApiStatusC) if err != nil { @@ -207,6 +199,14 @@ func FetchProgress(animeId int64, username string) (int, time.Time, int, string, if newProgress != -1 { return newProgress, updated, score, malApiStatusC, err } + // check on hold + newProgress, updated, score, err = FetchProgressOnState(animeId, username, malApiStatusH) + if err != nil { + return newProgress, updated, score, "", err + } + if newProgress != -1 { + return newProgress, updated, score, malApiStatusH, err + } // check dropped newProgress, updated, score, err = FetchProgressOnState(animeId, username, malApiStatusD) if err != nil {