Fix up errors after porting service accounts from develop

Signed-off-by: lzzy12 <jhashivam2020@gmail.com>
This commit is contained in:
lzzy12 2020-03-24 16:30:03 +05:30
parent 25856bfac0
commit 6ca2f479d5

View File

@ -3,6 +3,7 @@ import pickle
import urllib.parse as urlparse import urllib.parse as urlparse
from urllib.parse import parse_qs from urllib.parse import parse_qs
import json
import requests import requests
from google.auth.transport.requests import Request from google.auth.transport.requests import Request
@ -13,7 +14,7 @@ from googleapiclient.errors import HttpError
from googleapiclient.http import MediaFileUpload from googleapiclient.http import MediaFileUpload
from tenacity import * from tenacity import *
from bot import LOGGER, parent_id, DOWNLOAD_DIR, IS_TEAM_DRIVE, INDEX_URL, DOWNLOAD_STATUS_UPDATE_INTERVAL, \ from bot import LOGGER, parent_id, DOWNLOAD_DIR, IS_TEAM_DRIVE, INDEX_URL, \
USE_SERVICE_ACCOUNTS USE_SERVICE_ACCOUNTS
from bot.helper.ext_utils.bot_utils import * from bot.helper.ext_utils.bot_utils import *
from bot.helper.ext_utils.fs_utils import get_mime_type from bot.helper.ext_utils.fs_utils import get_mime_type
@ -31,6 +32,7 @@ class GoogleDriveHelper:
self.__REDIRECT_URI = "urn:ietf:wg:oauth:2.0:oob" self.__REDIRECT_URI = "urn:ietf:wg:oauth:2.0:oob"
self.__G_DRIVE_DIR_MIME_TYPE = "application/vnd.google-apps.folder" self.__G_DRIVE_DIR_MIME_TYPE = "application/vnd.google-apps.folder"
self.__G_DRIVE_BASE_DOWNLOAD_URL = "https://drive.google.com/uc?id={}&export=download" self.__G_DRIVE_BASE_DOWNLOAD_URL = "https://drive.google.com/uc?id={}&export=download"
self.__G_DRIVE_DIR_BASE_DOWNLOAD_URL = "https://drive.google.com/drive/folders/{}"
self.__listener = listener self.__listener = listener
self.__service = self.authorize() self.__service = self.authorize()
self.__listener = listener self.__listener = listener
@ -46,7 +48,6 @@ class GoogleDriveHelper:
self.updater = None self.updater = None
self.name = name self.name = name
self.update_interval = 3 self.update_interval = 3
self.service_account_count = len(os.listdir("accounts"))
def cancel(self): def cancel(self):
self.is_cancelled = True self.is_cancelled = True
@ -79,8 +80,7 @@ class GoogleDriveHelper:
self.uploaded_bytes += chunk_size self.uploaded_bytes += chunk_size
self.total_time += self.update_interval self.total_time += self.update_interval
@staticmethod def __upload_empty_file(self, path, file_name, mime_type, parent_id=None):
def __upload_empty_file(path, file_name, mime_type, parent_id=None):
media_body = MediaFileUpload(path, media_body = MediaFileUpload(path,
mimetype=mime_type, mimetype=mime_type,
resumable=False) resumable=False)
@ -96,7 +96,8 @@ class GoogleDriveHelper:
def switchServiceAccount(self): def switchServiceAccount(self):
global SERVICE_ACCOUNT_INDEX global SERVICE_ACCOUNT_INDEX
if SERVICE_ACCOUNT_INDEX == self.service_account_count - 1: service_account_count = len(os.listdir("accounts"))
if SERVICE_ACCOUNT_INDEX == service_account_count - 1:
SERVICE_ACCOUNT_INDEX = 0 SERVICE_ACCOUNT_INDEX = 0
SERVICE_ACCOUNT_INDEX += 1 SERVICE_ACCOUNT_INDEX += 1
LOGGER.info(f"Switching to {SERVICE_ACCOUNT_INDEX}.json service account") LOGGER.info(f"Switching to {SERVICE_ACCOUNT_INDEX}.json service account")