Improved sync
This commit is contained in:
parent
1806a623bc
commit
52c830ba88
@ -11,22 +11,34 @@ import (
|
|||||||
func main() {
|
func main() {
|
||||||
color.Yellow("Syncing Shoboi Anime")
|
color.Yellow("Syncing Shoboi Anime")
|
||||||
|
|
||||||
// Get a slice of all anime
|
// Priority queues
|
||||||
allAnime, _ := arn.AllAnime()
|
highPriority := []*arn.Anime{}
|
||||||
|
mediumPriority := []*arn.Anime{}
|
||||||
|
lowPriority := []*arn.Anime{}
|
||||||
|
|
||||||
// Iterate over the slice
|
for anime := range arn.MustStreamAnime() {
|
||||||
count := 0
|
if anime.GetMapping("shoboi/anime") != "" {
|
||||||
for _, anime := range allAnime {
|
continue
|
||||||
if sync(anime) {
|
|
||||||
count++
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Lower the request interval
|
switch anime.Status {
|
||||||
time.Sleep(2 * time.Second)
|
case "current":
|
||||||
|
highPriority = append(highPriority, anime)
|
||||||
|
case "upcoming":
|
||||||
|
mediumPriority = append(mediumPriority, anime)
|
||||||
|
default:
|
||||||
|
lowPriority = append(lowPriority, anime)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Log
|
color.Cyan("High priority queue (%d):", len(highPriority))
|
||||||
color.Green("Successfully added Shoboi IDs for %d anime", count)
|
refreshQueue(highPriority)
|
||||||
|
|
||||||
|
color.Cyan("Medium priority queue (%d):", len(mediumPriority))
|
||||||
|
refreshQueue(mediumPriority)
|
||||||
|
|
||||||
|
color.Cyan("Low priority queue (%d):", len(lowPriority))
|
||||||
|
refreshQueue(lowPriority)
|
||||||
|
|
||||||
// This is a lazy hack: Wait 5 minutes for goroutines to finish their remaining work.
|
// This is a lazy hack: Wait 5 minutes for goroutines to finish their remaining work.
|
||||||
time.Sleep(5 * time.Minute)
|
time.Sleep(5 * time.Minute)
|
||||||
@ -34,6 +46,18 @@ func main() {
|
|||||||
color.Green("Finished.")
|
color.Green("Finished.")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func refreshQueue(queue []*arn.Anime) {
|
||||||
|
count := 0
|
||||||
|
|
||||||
|
for _, anime := range queue {
|
||||||
|
if sync(anime) {
|
||||||
|
count++
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
color.Green("Added Shoboi IDs for %d anime", count)
|
||||||
|
}
|
||||||
|
|
||||||
func sync(anime *arn.Anime) bool {
|
func sync(anime *arn.Anime) bool {
|
||||||
// If we already have the ID, nothing to do here
|
// If we already have the ID, nothing to do here
|
||||||
if anime.GetMapping("shoboi/anime") != "" {
|
if anime.GetMapping("shoboi/anime") != "" {
|
||||||
|
Loading…
Reference in New Issue
Block a user