mirror of
https://github.com/ultrasn0w/huso.git
synced 2025-12-13 08:49:53 +01:00
Anime lists didn't age well 😵💫
This commit is contained in:
7
huso.go
7
huso.go
@@ -67,6 +67,7 @@ var (
|
||||
logOut *RingBuf
|
||||
buildTime string
|
||||
buildCommit string
|
||||
lastAnnounce *SomewhatThreadSafeTime
|
||||
)
|
||||
|
||||
func main() {
|
||||
@@ -107,7 +108,7 @@ func main() {
|
||||
log.Fatal(err)
|
||||
}
|
||||
defer searchCache.Close()
|
||||
animeListCache, err = bigcache.NewBigCache(bigcache.DefaultConfig(24 * time.Minute))
|
||||
animeListCache, err = bigcache.NewBigCache(bigcache.DefaultConfig(15 * time.Minute))
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
@@ -126,6 +127,10 @@ func main() {
|
||||
}
|
||||
defer db.Close()
|
||||
|
||||
lastAnnounce = &SomewhatThreadSafeTime{
|
||||
stamp: time.Now().Add(-1 * time.Hour),
|
||||
}
|
||||
|
||||
color.Infoln("NutsDB connected")
|
||||
logOut.WriteLine("🗃️ NutsDB connected")
|
||||
|
||||
|
||||
10
klotz.go
10
klotz.go
@@ -1,6 +1,9 @@
|
||||
package main
|
||||
|
||||
import "time"
|
||||
import (
|
||||
"sync"
|
||||
"time"
|
||||
)
|
||||
|
||||
type AnimeUser struct {
|
||||
Anime int64 `json:"anime"`
|
||||
@@ -328,3 +331,8 @@ type MovieChart struct {
|
||||
AvgScore float64 `json:"avgScore"`
|
||||
UserCount int `json:"userCount"`
|
||||
}
|
||||
|
||||
type SomewhatThreadSafeTime struct {
|
||||
sync.Mutex
|
||||
stamp time.Time
|
||||
}
|
||||
|
||||
@@ -82,10 +82,10 @@ func GetAnimeDetailData(animeId int64) (*Anime, []byte, error) {
|
||||
return &anime, data, err
|
||||
}
|
||||
|
||||
func GetUserAnimeListData(username, status string, refetch bool) (*AnimeListMal, []byte, error) {
|
||||
func GetUserAnimeListData(username, status string) (*AnimeListMal, []byte, error) {
|
||||
var list AnimeListMal
|
||||
data, err := animeListCache.Get(username + status)
|
||||
if refetch || err != nil {
|
||||
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&nsfw=true")
|
||||
|
||||
22
ober.go
22
ober.go
@@ -692,26 +692,18 @@ func processUpdateReq(ctx *fasthttp.RequestCtx, update bool) {
|
||||
if update {
|
||||
// anime exitsts => save
|
||||
// get watch progress
|
||||
progress, updated, _, listState, _ := FetchProgress(anime.Anime, username, false)
|
||||
progress, updated, _, listState, _ := FetchProgress(anime.Anime, username)
|
||||
// anime is already completed big baka user
|
||||
if listState == malApiStatusC {
|
||||
// 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
|
||||
}
|
||||
ctx.WriteString("Du hast schon fertig geschaut bro")
|
||||
ctx.SetStatusCode(fasthttp.StatusConflict)
|
||||
return
|
||||
}
|
||||
// anime is already dropped big baka user
|
||||
if listState == malApiStatusD {
|
||||
// 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
|
||||
}
|
||||
ctx.WriteString("Du hast schon gedropped bro")
|
||||
ctx.SetStatusCode(fasthttp.StatusConflict)
|
||||
return
|
||||
}
|
||||
animeData, err = AddUserToAnime(username, userId, anime.Anime, progress, updated)
|
||||
} else {
|
||||
|
||||
@@ -12,7 +12,7 @@ import (
|
||||
)
|
||||
|
||||
func Arbeiten() {
|
||||
for range time.Tick(20 * time.Minute) {
|
||||
for range time.Tick(10 * time.Minute) {
|
||||
Arbeit()
|
||||
}
|
||||
}
|
||||
@@ -27,15 +27,9 @@ func Arbeit() {
|
||||
}
|
||||
} else {
|
||||
cleared := 0
|
||||
checkDate := time.Now().Add(-1 * time.Hour)
|
||||
lastAnnounce.Lock()
|
||||
defer lastAnnounce.Unlock()
|
||||
newCheckDate := time.Now()
|
||||
data, err := animeListCache.Get(bucketAppoint)
|
||||
if err == nil {
|
||||
nanora, err := BytesToInt64(data)
|
||||
if err == nil {
|
||||
checkDate = time.Unix(0, nanora)
|
||||
}
|
||||
}
|
||||
for _, a := range appoints {
|
||||
if a.Time.Add(22 * time.Hour).Before(newCheckDate) {
|
||||
// appointment expired
|
||||
@@ -48,13 +42,13 @@ func Arbeit() {
|
||||
cleared++
|
||||
}
|
||||
} else {
|
||||
if checkDate.Add(time.Hour).Before(a.Time) && newCheckDate.Add(time.Hour).After(a.Time) {
|
||||
if lastAnnounce.stamp.Add(time.Hour).Before(a.Time) && newCheckDate.Add(time.Hour).After(a.Time) {
|
||||
// This has not happened and is happening soon
|
||||
go AnnounceBomb(a.Anime, a.Time.Unix(), time.Until(a.Time.Add(-25*time.Minute)))
|
||||
}
|
||||
}
|
||||
}
|
||||
animeListCache.Set(bucketAppoint, Int64ToByte(newCheckDate.UnixNano()))
|
||||
lastAnnounce.stamp = newCheckDate
|
||||
if cleared > 0 {
|
||||
color.Infof("Cleared %d expired appointments\n", cleared)
|
||||
logOut.WriteLine(fmt.Sprintf("♻️ Cleared %d expired appointments", cleared))
|
||||
@@ -70,14 +64,19 @@ func Arbeit() {
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// ACTUALLY STUPID ENOUGH TO FIX A LOT OF PROBLEMS
|
||||
animeListCache.Reset()
|
||||
|
||||
color.Infoln("Animelisten abfragen...")
|
||||
logOut.WriteLine("📜 Animelisten abfragen...")
|
||||
//logOut.WriteLine("📜 Animelisten abfragen...")
|
||||
|
||||
count := 0
|
||||
// iterate anime
|
||||
for _, a := range animesUsers {
|
||||
// iterate users
|
||||
for _, u := range a.Users {
|
||||
newProgress, updated, score, listState, err := FetchProgress(a.Anime, u.Username, true)
|
||||
newProgress, updated, score, listState, err := FetchProgress(a.Anime, u.Username)
|
||||
if err != nil {
|
||||
color.Errorln(err.Error())
|
||||
logOut.WriteError(err)
|
||||
@@ -123,8 +122,10 @@ func Arbeit() {
|
||||
count++
|
||||
}
|
||||
}
|
||||
color.Infof("%d Sachen aktualisiert\n", count)
|
||||
logOut.WriteLine(fmt.Sprintf("📜 %d Sachen aktualisiert", count))
|
||||
if count > 0 {
|
||||
color.Infof("%d Sachen aktualisiert\n", count)
|
||||
logOut.WriteLine(fmt.Sprintf("📜 %d Sachen aktualisiert", count))
|
||||
}
|
||||
}
|
||||
|
||||
func BissleArbeiten() {
|
||||
|
||||
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, refetch bool) (int, time.Time, int, string, error) {
|
||||
func FetchProgress(animeId int64, username string) (int, time.Time, int, string, error) {
|
||||
// check watching first
|
||||
newProgress, updated, score, err := FetchProgressOnState(animeId, username, malApiStatusW, refetch)
|
||||
newProgress, updated, score, err := FetchProgressOnState(animeId, username, malApiStatusW)
|
||||
if err != nil {
|
||||
return newProgress, updated, score, "", err
|
||||
}
|
||||
@@ -204,7 +204,7 @@ func FetchProgress(animeId int64, username string, refetch bool) (int, time.Time
|
||||
return newProgress, updated, score, malApiStatusW, err
|
||||
}
|
||||
// check completed
|
||||
newProgress, updated, score, err = FetchProgressOnState(animeId, username, malApiStatusC, refetch)
|
||||
newProgress, updated, score, err = FetchProgressOnState(animeId, username, malApiStatusC)
|
||||
if err != nil {
|
||||
return newProgress, updated, score, "", err
|
||||
}
|
||||
@@ -212,7 +212,7 @@ func FetchProgress(animeId int64, username string, refetch bool) (int, time.Time
|
||||
return newProgress, updated, score, malApiStatusC, err
|
||||
}
|
||||
// check on hold
|
||||
newProgress, updated, score, err = FetchProgressOnState(animeId, username, malApiStatusH, refetch)
|
||||
newProgress, updated, score, err = FetchProgressOnState(animeId, username, malApiStatusH)
|
||||
if err != nil {
|
||||
return newProgress, updated, score, "", err
|
||||
}
|
||||
@@ -220,7 +220,7 @@ func FetchProgress(animeId int64, username string, refetch bool) (int, time.Time
|
||||
return newProgress, updated, score, malApiStatusH, err
|
||||
}
|
||||
// check dropped
|
||||
newProgress, updated, score, err = FetchProgressOnState(animeId, username, malApiStatusD, refetch)
|
||||
newProgress, updated, score, err = FetchProgressOnState(animeId, username, malApiStatusD)
|
||||
if err != nil {
|
||||
return newProgress, updated, score, "", err
|
||||
}
|
||||
@@ -231,8 +231,8 @@ func FetchProgress(animeId int64, username string, refetch bool) (int, time.Time
|
||||
return 0, updated, 0, "", nil
|
||||
}
|
||||
|
||||
func FetchProgressOnState(animeId int64, username, malStatus string, refetch bool) (int, time.Time, int, error) {
|
||||
list, _, err := GetUserAnimeListData(username, malStatus, refetch)
|
||||
func FetchProgressOnState(animeId int64, username, malStatus string) (int, time.Time, int, error) {
|
||||
list, _, err := GetUserAnimeListData(username, malStatus)
|
||||
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, false)
|
||||
progress, _, score, err := FetchProgressOnState(c.Anime, u.Username, malApiStatusC)
|
||||
if err != nil {
|
||||
color.Errorln(err.Error())
|
||||
continue
|
||||
|
||||
Reference in New Issue
Block a user