Can now refresh a single anime in refresh-episodes

This commit is contained in:
Eduard Urbach 2017-09-24 03:39:26 +02:00
parent 7bce362eeb
commit eb4b4c7b54
2 changed files with 60 additions and 20 deletions

View File

@ -12,6 +12,10 @@ import (
func main() {
color.Yellow("Refreshing episode information for each anime.")
if InvokeShellArgs() {
return
}
highPriority := []*arn.Anime{}
mediumPriority := []*arn.Anime{}
lowPriority := []*arn.Anime{}
@ -32,34 +36,38 @@ func main() {
}
color.Cyan("High priority queue (%d):", len(highPriority))
refresh(highPriority)
refreshQueue(highPriority)
color.Cyan("Medium priority queue (%d):", len(mediumPriority))
refresh(mediumPriority)
refreshQueue(mediumPriority)
color.Cyan("Low priority queue (%d):", len(lowPriority))
refresh(lowPriority)
refreshQueue(lowPriority)
color.Green("Finished.")
}
func refresh(queue []*arn.Anime) {
func refreshQueue(queue []*arn.Anime) {
for _, anime := range queue {
fmt.Println(anime.ID, "|", anime.Title.Canonical, "|", anime.GetMapping("shoboi/anime"))
episodeCount := len(anime.Episodes().Items)
availableEpisodeCount := anime.Episodes().AvailableCount()
err := anime.RefreshEpisodes()
if err != nil {
if strings.Contains(err.Error(), "missing a Shoboi ID") {
continue
}
color.Red(err.Error())
} else {
fmt.Println("+"+strconv.Itoa(len(anime.Episodes().Items)-episodeCount)+" airing", "|", "+"+strconv.Itoa(anime.Episodes().AvailableCount()-availableEpisodeCount)+" available")
}
refresh(anime)
}
}
func refresh(anime *arn.Anime) {
fmt.Println(anime.ID, "|", anime.Title.Canonical, "|", anime.GetMapping("shoboi/anime"))
episodeCount := len(anime.Episodes().Items)
availableEpisodeCount := anime.Episodes().AvailableCount()
err := anime.RefreshEpisodes()
if err != nil {
if strings.Contains(err.Error(), "missing a Shoboi ID") {
return
}
color.Red(err.Error())
} else {
fmt.Println("+"+strconv.Itoa(len(anime.Episodes().Items)-episodeCount)+" airing", "|", "+"+strconv.Itoa(anime.Episodes().AvailableCount()-availableEpisodeCount)+" available")
}
}

View File

@ -0,0 +1,32 @@
package main
import (
"flag"
"github.com/animenotifier/arn"
)
// Shell parameters
var animeID string
// Shell flags
func init() {
flag.StringVar(&animeID, "id", "", "ID of the anime you want to refresh")
flag.Parse()
}
// InvokeShellArgs ...
func InvokeShellArgs() bool {
if animeID != "" {
anime, err := arn.GetAnime(animeID)
if err != nil {
panic(err)
}
refresh(anime)
return true
}
return false
}