From 8ee11a691d1c80b6f60bc07900440e67fc9656f2 Mon Sep 17 00:00:00 2001 From: Jeroen Oudshoorn Date: Fri, 13 Oct 2023 00:11:41 +0200 Subject: [PATCH] v2.4.7 Signed-off-by: Jeroen Oudshoorn --- pwnagotchi/google/cmd.py | 53 ++++++++++++++++++++-------------------- 1 file changed, 26 insertions(+), 27 deletions(-) diff --git a/pwnagotchi/google/cmd.py b/pwnagotchi/google/cmd.py index a520e7ef..36bcb7f2 100644 --- a/pwnagotchi/google/cmd.py +++ b/pwnagotchi/google/cmd.py @@ -34,7 +34,7 @@ def handle_cmd(args): if args.plugincmd == 'auth': return auth() elif args.plugincmd == 'refresh': - return refresh(args) + return refresh() raise NotImplementedError() @@ -57,35 +57,34 @@ def auth(): return 0 -def refresh(args): - if int(args): - # refresh token for x amount of time (seconds) - gauth = GoogleAuth(settings_file="settings.yaml") - try: - # Try to load saved client credentials - gauth.LoadCredentialsFile("credentials.json") - except pydrive2.auth.InvalidCredentialsError: - print(gauth.GetAuthUrl()) - user_input = input("Please copy this URL into a browser, " - "complete the verification and then copy/paste the code from addressbar.") - gauth.Auth(user_input) +def refresh(): + # refresh token for x amount of time (seconds) + gauth = GoogleAuth(settings_file="settings.yaml") + try: + # Try to load saved client credentials + gauth.LoadCredentialsFile("credentials.json") + except pydrive2.auth.InvalidCredentialsError: + print(gauth.GetAuthUrl()) + user_input = input("Please copy this URL into a browser, " + "complete the verification and then copy/paste the code from addressbar.") + gauth.Auth(user_input) - if gauth.access_token_expired: - if gauth.credentials is not None: - try: - # Refresh the token - gauth.Refresh() - except pydrive2.auth.RefreshError: - print(gauth.GetAuthUrl()) - user_input = input("Please copy this URL into a browser, " - "complete the verification and then copy/paste the code from addressbar.") - gauth.Auth(user_input) - else: + if gauth.access_token_expired: + if gauth.credentials is not None: + try: + # Refresh the token + gauth.Refresh() + except pydrive2.auth.RefreshError: print(gauth.GetAuthUrl()) user_input = input("Please copy this URL into a browser, " "complete the verification and then copy/paste the code from addressbar.") gauth.Auth(user_input) - gauth.Authorize() - gauth.SaveCredentialsFile("credentials.json") - print("No refresh is required.") + else: + print(gauth.GetAuthUrl()) + user_input = input("Please copy this URL into a browser, " + "complete the verification and then copy/paste the code from addressbar.") + gauth.Auth(user_input) + gauth.Authorize() + gauth.SaveCredentialsFile("credentials.json") + print("No refresh is required.") return 0