79 lines
1.5 KiB
Go
Raw Normal View History

2017-06-06 22:08:43 +02:00
package main
import (
2017-06-07 21:12:59 +02:00
"sort"
2017-06-06 22:08:43 +02:00
"github.com/animenotifier/arn"
"github.com/fatih/color"
)
2017-09-30 16:04:13 +02:00
const (
2017-10-02 01:30:50 +02:00
currentlyAiringBonus = 5.0
2017-09-30 16:04:13 +02:00
popularityThreshold = 5
2017-10-02 01:30:50 +02:00
popularityPenalty = 8.0
watchingPopularityWeight = 0.3
plannedPopularityWeight = 0.2
2017-09-30 16:04:13 +02:00
)
2017-07-17 23:49:11 +02:00
2017-06-06 22:08:43 +02:00
func main() {
color.Yellow("Caching airing anime")
animeList, err := arn.GetAiringAnime()
if err != nil {
color.Red("Failed fetching airing anime")
color.Red(err.Error())
return
}
2017-06-07 21:12:59 +02:00
sort.Slice(animeList, func(i, j int) bool {
2017-09-30 16:04:13 +02:00
a := animeList[i]
b := animeList[j]
scoreA := a.Rating.Overall
scoreB := b.Rating.Overall
2017-07-17 23:49:11 +02:00
2017-09-30 16:04:13 +02:00
if a.Status == "current" {
2017-07-17 23:49:11 +02:00
scoreA += currentlyAiringBonus
}
2017-09-30 16:04:13 +02:00
if b.Status == "current" {
2017-07-17 23:49:11 +02:00
scoreB += currentlyAiringBonus
}
2017-09-30 16:04:13 +02:00
if a.Popularity.Total() < popularityThreshold {
scoreA -= popularityPenalty
}
if b.Popularity.Total() < popularityThreshold {
scoreB -= popularityPenalty
}
scoreA += float64(a.Popularity.Watching) * watchingPopularityWeight
scoreB += float64(b.Popularity.Watching) * watchingPopularityWeight
2017-10-02 01:30:50 +02:00
scoreA += float64(a.Popularity.Planned) * plannedPopularityWeight
scoreB += float64(b.Popularity.Planned) * plannedPopularityWeight
2017-07-17 23:49:11 +02:00
return scoreA > scoreB
2017-06-07 21:12:59 +02:00
})
2017-06-06 22:08:43 +02:00
// Convert to small anime list
cache := &arn.ListOfIDs{}
for _, anime := range animeList {
cache.IDList = append(cache.IDList, anime.ID)
}
println(len(cache.IDList))
2017-06-14 17:16:03 +02:00
saveErr := arn.DB.Set("Cache", "airing anime", cache)
2017-06-06 22:08:43 +02:00
if saveErr != nil {
color.Red("Error saving airing anime")
color.Red(saveErr.Error())
return
}
color.Green("Finished.")
}