From 21823890e0d3800715af153cdb75f99480114c5f Mon Sep 17 00:00:00 2001 From: Eduard Urbach Date: Tue, 3 Jul 2018 12:27:34 +0900 Subject: [PATCH] Removed time.Sleep statements in jobs --- .../download-character-images.go | 3 -- .../soundtrack-download.go | 4 -- .../add-character-created-date.go | 2 - .../delete-unused-characters.go | 2 - .../fix-wrong-ids-in-animelists.go | 3 -- .../generate-anime-ids/generate-anime-ids.go | 1 - .../mark-month-as-current.go | 2 - .../merge-duplicate-characters.go | 3 -- .../remove-character-borders.go | 2 - .../user-set-social-id/user-set-social-id.go | 49 +++++++++++++++++++ 10 files changed, 49 insertions(+), 22 deletions(-) create mode 100644 patches/user-set-social-id/user-set-social-id.go diff --git a/jobs/download-character-images/download-character-images.go b/jobs/download-character-images/download-character-images.go index 38485e33..84a52f94 100644 --- a/jobs/download-character-images/download-character-images.go +++ b/jobs/download-character-images/download-character-images.go @@ -4,7 +4,6 @@ import ( "fmt" "net/http" "sort" - "time" _ "image/gif" _ "image/jpeg" @@ -33,8 +32,6 @@ func main() { fmt.Printf("[%d / %d] %s %s\n", index+1, len(characters), character.ID, color.CyanString(character.String())) download(character.ID) } - - time.Sleep(time.Second) } func download(characterID string) { diff --git a/jobs/soundtrack-download/soundtrack-download.go b/jobs/soundtrack-download/soundtrack-download.go index 1608b27d..b79212c6 100644 --- a/jobs/soundtrack-download/soundtrack-download.go +++ b/jobs/soundtrack-download/soundtrack-download.go @@ -2,7 +2,6 @@ package main import ( "fmt" - "time" "github.com/animenotifier/arn" "github.com/fatih/color" @@ -32,8 +31,5 @@ func main() { // Save the file information track.Save() - - // Delay a little - time.Sleep(delayBetweenRequests) } } diff --git a/patches/add-character-created-date/add-character-created-date.go b/patches/add-character-created-date/add-character-created-date.go index 6567b954..1fc1a84b 100644 --- a/patches/add-character-created-date/add-character-created-date.go +++ b/patches/add-character-created-date/add-character-created-date.go @@ -40,6 +40,4 @@ func main() { character.Save() } - - time.Sleep(1 * time.Second) } diff --git a/patches/delete-unused-characters/delete-unused-characters.go b/patches/delete-unused-characters/delete-unused-characters.go index 00f88aa2..8678dd64 100644 --- a/patches/delete-unused-characters/delete-unused-characters.go +++ b/patches/delete-unused-characters/delete-unused-characters.go @@ -2,7 +2,6 @@ package main import ( "fmt" - "time" "github.com/animenotifier/arn" "github.com/fatih/color" @@ -55,5 +54,4 @@ func main() { } fmt.Println(len(used), len(characters)) - time.Sleep(2 * time.Second) } diff --git a/patches/fix-wrong-ids-in-animelists/fix-wrong-ids-in-animelists.go b/patches/fix-wrong-ids-in-animelists/fix-wrong-ids-in-animelists.go index 78b92b80..db039af2 100644 --- a/patches/fix-wrong-ids-in-animelists/fix-wrong-ids-in-animelists.go +++ b/patches/fix-wrong-ids-in-animelists/fix-wrong-ids-in-animelists.go @@ -2,7 +2,6 @@ package main import ( "fmt" - "time" "github.com/animenotifier/arn" "github.com/fatih/color" @@ -40,6 +39,4 @@ func main() { animeList.Save() } } - - time.Sleep(time.Second) } diff --git a/patches/generate-anime-ids/generate-anime-ids.go b/patches/generate-anime-ids/generate-anime-ids.go index a9bd59ae..89948d4b 100644 --- a/patches/generate-anime-ids/generate-anime-ids.go +++ b/patches/generate-anime-ids/generate-anime-ids.go @@ -21,6 +21,5 @@ func main() { // newID := arn.GenerateID("Anime") // fmt.Printf("[%d / %d] Old [%s] New [%s] %s\n", counter+1, len(allAnime), color.YellowString(anime.ID), color.GreenString(newID), anime) // anime.SetID(newID) - // time.Sleep(100 * time.Millisecond) // } } diff --git a/patches/mark-month-as-current/mark-month-as-current.go b/patches/mark-month-as-current/mark-month-as-current.go index cc89b452..cb5c875f 100644 --- a/patches/mark-month-as-current/mark-month-as-current.go +++ b/patches/mark-month-as-current/mark-month-as-current.go @@ -27,6 +27,4 @@ func main() { anime.Save() } } - - time.Sleep(1 * time.Second) } diff --git a/patches/merge-duplicate-characters/merge-duplicate-characters.go b/patches/merge-duplicate-characters/merge-duplicate-characters.go index 2fa8aca5..9c7dfd68 100644 --- a/patches/merge-duplicate-characters/merge-duplicate-characters.go +++ b/patches/merge-duplicate-characters/merge-duplicate-characters.go @@ -3,7 +3,6 @@ package main import ( "fmt" "sort" - "time" "github.com/animenotifier/arn" "github.com/fatih/color" @@ -41,6 +40,4 @@ func main() { } } } - - time.Sleep(1 * time.Second) } diff --git a/patches/remove-character-borders/remove-character-borders.go b/patches/remove-character-borders/remove-character-borders.go index 987b8b3b..e75a8085 100644 --- a/patches/remove-character-borders/remove-character-borders.go +++ b/patches/remove-character-borders/remove-character-borders.go @@ -6,7 +6,6 @@ import ( "image" "os" "path" - "time" "github.com/animenotifier/arn" "github.com/fatih/color" @@ -20,7 +19,6 @@ import ( func main() { defer color.Green("Finished.") defer arn.Node.Close() - defer time.Sleep(time.Second) characters := arn.FilterCharacters(func(character *arn.Character) bool { return character.HasImage() diff --git a/patches/user-set-social-id/user-set-social-id.go b/patches/user-set-social-id/user-set-social-id.go new file mode 100644 index 00000000..1aa9998b --- /dev/null +++ b/patches/user-set-social-id/user-set-social-id.go @@ -0,0 +1,49 @@ +package main + +import ( + "flag" + + "github.com/animenotifier/arn" + "github.com/fatih/color" +) + +// Shell parameters +var nick string +var service string +var serviceID string + +// Shell flags +func init() { + flag.StringVar(&nick, "nick", "", "Nick of the user") + flag.StringVar(&service, "service", "", "Service name (Google or Facebook)") + flag.StringVar(&serviceID, "serviceID", "", "ID of the user on the given service") + flag.Parse() +} + +func main() { + if nick == "" || service == "" || serviceID == "" { + flag.Usage() + return + } + + color.Yellow("Updating user service ID") + + defer color.Green("Finished.") + defer arn.Node.Close() + + user, err := arn.GetUserByNick(nick) + arn.PanicOnError(err) + + switch service { + case "Google": + user.ConnectGoogle(serviceID) + + case "Facebook": + user.ConnectFacebook(serviceID) + + default: + panic("Unknown service") + } + + user.Save() +}