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