Don't depend on bot to run for generate_gdrive_token.py

This commit is contained in:
lzzy12 2019-11-07 14:48:35 +05:30
parent ac39b7e682
commit da622c04be
2 changed files with 23 additions and 4 deletions

View File

@ -42,7 +42,7 @@ class DownloadHelper:
if self.__is_torrent:
# Waiting for the actual gid
download = self.__get_download()
while download.is_complete != True: # Check every few seconds
while download.is_complete: # Check every few seconds
status_list = get_download_status_list()
index = get_download_index(status_list, self.__get_download().gid)
download = self.__get_download()

View File

@ -1,4 +1,23 @@
from bot.helper.mirror_utils.gdriveTools import GoogleDriveHelper
import pickle
import os
from google_auth_oauthlib.flow import InstalledAppFlow
from google.auth.transport.requests import Request
drive = GoogleDriveHelper()
drive.authorize()
credentials = None
__G_DRIVE_TOKEN_FILE = "token.pickle"
__OAUTH_SCOPE = "https://www.googleapis.com/auth/drive.file"
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())
else:
flow = InstalledAppFlow.from_client_secrets_file(
'credentials.json', __OAUTH_SCOPE)
credentials = flow.run_console(port=0)
# Save the credentials for the next run
with open(__G_DRIVE_TOKEN_FILE, 'wb') as token:
pickle.dump(credentials, token)