From 1ee4619310a31d4b6da5e747629879ac9e878d1d Mon Sep 17 00:00:00 2001 From: Eduard Urbach Date: Thu, 9 Nov 2017 14:36:47 +0100 Subject: [PATCH] Added shell flags --- jobs/anime-images/anime-images.go | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/jobs/anime-images/anime-images.go b/jobs/anime-images/anime-images.go index 2bdd1fb1..197c72d9 100644 --- a/jobs/anime-images/anime-images.go +++ b/jobs/anime-images/anime-images.go @@ -1,10 +1,12 @@ package main import ( + "flag" "fmt" "os" "path" "runtime" + "sort" "strings" "time" @@ -19,7 +21,18 @@ import ( "github.com/fatih/color" ) -var ticker = time.NewTicker(100 * time.Millisecond) +var ticker = time.NewTicker(200 * time.Millisecond) + +// Shell parameters +var from int +var to int + +// Shell flags +func init() { + flag.IntVar(&from, "from", 0, "From index") + flag.IntVar(&to, "to", 0, "To index") + flag.Parse() +} func main() { color.Yellow("Downloading anime images") @@ -27,6 +40,20 @@ func main() { allAnime := arn.AllAnime() + sort.Slice(allAnime, func(i, j int) bool { + return allAnime[i].Title.Canonical < allAnime[j].Title.Canonical + }) + + if from < 0 { + from = 0 + } + + if to > len(allAnime) { + to = len(allAnime) + } + + allAnime = allAnime[from:to] + for index, anime := range allAnime { fmt.Printf("%d / %d\n", index+1, len(allAnime)) work(anime)