75 lines
1.4 KiB
Go
Raw Normal View History

2017-06-06 20:08:43 +00:00
package main
import (
2017-06-07 19:12:59 +00:00
"sort"
2017-06-06 20:08:43 +00:00
"github.com/animenotifier/arn"
"github.com/fatih/color"
)
2017-09-30 14:04:13 +00:00
const (
currentlyAiringBonus = 4.0
popularityThreshold = 5
popularityPenalty = 4.0
watchingPopularityWeight = 0.1
)
2017-07-17 21:49:11 +00:00
2017-06-06 20:08:43 +00: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 19:12:59 +00:00
sort.Slice(animeList, func(i, j int) bool {
2017-09-30 14:04:13 +00:00
a := animeList[i]
b := animeList[j]
scoreA := a.Rating.Overall
scoreB := b.Rating.Overall
2017-07-17 21:49:11 +00:00
2017-09-30 14:04:13 +00:00
if a.Status == "current" {
2017-07-17 21:49:11 +00:00
scoreA += currentlyAiringBonus
}
2017-09-30 14:04:13 +00:00
if b.Status == "current" {
2017-07-17 21:49:11 +00:00
scoreB += currentlyAiringBonus
}
2017-09-30 14:04:13 +00: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-07-17 21:49:11 +00:00
return scoreA > scoreB
2017-06-07 19:12:59 +00:00
})
2017-06-06 20:08:43 +00: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 15:16:03 +00:00
saveErr := arn.DB.Set("Cache", "airing anime", cache)
2017-06-06 20:08:43 +00:00
if saveErr != nil {
color.Red("Error saving airing anime")
color.Red(saveErr.Error())
return
}
color.Green("Finished.")
}