From 8dee90b18d28856009044d4c34bb8676a8df0b41 Mon Sep 17 00:00:00 2001 From: Shubham Gopale Date: Fri, 13 May 2022 09:12:53 +0530 Subject: [PATCH] fix drive token generation and update readme Signed-off-by: shubhindia --- README.md | 2 +- generate_drive_token.py | 14 +++++++++----- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 784c1aa2d..354700f87 100644 --- a/README.md +++ b/README.md @@ -79,7 +79,7 @@ Note: You can limit maximum concurrent downloads by changing the value of MAX_CO - Visit the [Google Cloud Console](https://console.developers.google.com/apis/credentials) - Go to the OAuth Consent tab, fill it, and save. - Go to the Credentials tab and click Create Credentials -> OAuth Client ID -- Choose Other and Create. +- Choose `Desktop App` as Application type and Create. - Use the download button to download your credentials. - Move that file to the root of mirror-bot, and rename it to credentials.json - Visit [Google API page](https://console.developers.google.com/apis/library) diff --git a/generate_drive_token.py b/generate_drive_token.py index eafad5a72..625024313 100644 --- a/generate_drive_token.py +++ b/generate_drive_token.py @@ -9,14 +9,18 @@ if os.path.exists(__G_DRIVE_TOKEN_FILE): with open(__G_DRIVE_TOKEN_FILE, 'rb') as f: credentials = pickle.load(f) - if credentials is None or not credentials.valid: - if credentials and credentials.expired and credentials.refresh_token: - credentials.refresh(Request()) + if ( + (credentials is None or not credentials.valid) + and credentials + and credentials.expired + and credentials.refresh_token + ): + credentials.refresh(Request()) else: flow = InstalledAppFlow.from_client_secrets_file( 'credentials.json', __OAUTH_SCOPE) - credentials = flow.run_console(port=0) + credentials = flow.run_local_server(port=0) # Save the credentials for the next run with open(__G_DRIVE_TOKEN_FILE, 'wb') as token: - pickle.dump(credentials, token) \ No newline at end of file + pickle.dump(credentials, token)