From c60c171a2f25f79d149abbbacef0bb7215756325 Mon Sep 17 00:00:00 2001 From: Eduard Urbach Date: Thu, 12 Apr 2018 19:05:05 +0200 Subject: [PATCH] Added shell parameters to MAL jobs --- jobs/mal-parse/mal-parse.go | 8 ++++++-- jobs/mal-parse/shell.go | 37 +++++++++++++++++++++++++++++++++++++ jobs/mal-sync/mal-sync.go | 5 +++++ jobs/mal-sync/shell.go | 36 ++++++++++++++++++++++++++++++++++++ 4 files changed, 84 insertions(+), 2 deletions(-) create mode 100644 jobs/mal-parse/shell.go create mode 100644 jobs/mal-sync/shell.go diff --git a/jobs/mal-parse/mal-parse.go b/jobs/mal-parse/mal-parse.go index eb0cdb63..5c6da1a3 100644 --- a/jobs/mal-parse/mal-parse.go +++ b/jobs/mal-parse/mal-parse.go @@ -5,6 +5,7 @@ import ( "errors" "fmt" "os" + "path" "path/filepath" "strings" @@ -21,9 +22,12 @@ func main() { defer color.Green("Finished.") defer arn.Node.Close() - // readFile("../mal-download/files/anime-31240.html") + // Invoke via parameters + if InvokeShellArgs() { + return + } - filepath.Walk("../mal-download/files", func(name string, info os.FileInfo, err error) error { + filepath.Walk(path.Join(arn.Root, "jobs/mal-download/files"), func(name string, info os.FileInfo, err error) error { if err != nil { fmt.Println(err) return err diff --git a/jobs/mal-parse/shell.go b/jobs/mal-parse/shell.go new file mode 100644 index 00000000..3cd11cea --- /dev/null +++ b/jobs/mal-parse/shell.go @@ -0,0 +1,37 @@ +package main + +import ( + "flag" + "path" + + "github.com/animenotifier/arn" +) + +// Shell parameters +var animeID string + +// Shell flags +func init() { + flag.StringVar(&animeID, "id", "", "ID of the notify.moe anime you want to refresh") + flag.Parse() +} + +// InvokeShellArgs ... +func InvokeShellArgs() bool { + if animeID != "" { + anime, err := arn.GetAnime(animeID) + + if err != nil { + panic(err) + } + + if anime.GetMapping("myanimelist/anime") == "" { + panic("No MAL ID") + } + + readFile(path.Join(arn.Root, "jobs/mal-download/files", "anime-"+anime.GetMapping("myanimelist/anime")+".html")) + return true + } + + return false +} diff --git a/jobs/mal-sync/mal-sync.go b/jobs/mal-sync/mal-sync.go index cbf72277..a6d3833a 100644 --- a/jobs/mal-sync/mal-sync.go +++ b/jobs/mal-sync/mal-sync.go @@ -19,6 +19,11 @@ func main() { defer color.Green("Finished.") defer arn.Node.Close() + // Invoke via parameters + if InvokeShellArgs() { + return + } + // Sync the most important ones first allAnime := arn.AllAnime() arn.SortAnimeByQuality(allAnime) diff --git a/jobs/mal-sync/shell.go b/jobs/mal-sync/shell.go new file mode 100644 index 00000000..0300b24e --- /dev/null +++ b/jobs/mal-sync/shell.go @@ -0,0 +1,36 @@ +package main + +import ( + "flag" + + "github.com/animenotifier/arn" +) + +// Shell parameters +var animeID string + +// Shell flags +func init() { + flag.StringVar(&animeID, "id", "", "ID of the notify.moe anime you want to refresh") + flag.Parse() +} + +// InvokeShellArgs ... +func InvokeShellArgs() bool { + if animeID != "" { + anime, err := arn.GetAnime(animeID) + + if err != nil { + panic(err) + } + + if anime.GetMapping("myanimelist/anime") == "" { + panic("No MAL ID") + } + + sync(anime, anime.GetMapping("myanimelist/anime")) + return true + } + + return false +}