diff --git a/bot/helper/bot_utils.py b/bot/helper/bot_utils.py index 0bba8cf..b2287ee 100644 --- a/bot/helper/bot_utils.py +++ b/bot/helper/bot_utils.py @@ -28,13 +28,11 @@ def get_download_str(): def get_readable_message(progress_list: list = download_dict.values()): msg = "" for status in progress_list: - msg += "Name: {}\n" \ - "status: {}\n" \ - "Downloaded: {} of {}\n" \ - "Speed: {}\n" \ - "ETA: {}\n\n".format(status.name(), status.status(), - status.progress(), status.size(), - status.speed(), status.eta()) + msg += f'Name: {status.name()}\n' \ + f'status: {status.status()}\n' \ + f'Downloaded: {status.progress()} of {status.size()}\n' \ + f'Speed: {status.speed()}\n' \ + f'ETA: {status.eta()}\n\n' return msg diff --git a/bot/helper/download_status.py b/bot/helper/download_status.py index 1e0daf2..8ece80c 100644 --- a/bot/helper/download_status.py +++ b/bot/helper/download_status.py @@ -32,7 +32,7 @@ class DownloadStatus: return self.__download.name def path(self): - return "{}{}".format(DOWNLOAD_DIR, self.__uid) + return f"{DOWNLOAD_DIR}{self.__uid}" def size(self): return self.__download.total_length_string() diff --git a/bot/helper/fs_utils.py b/bot/helper/fs_utils.py index 50d58d5..71f3a6f 100644 --- a/bot/helper/fs_utils.py +++ b/bot/helper/fs_utils.py @@ -8,7 +8,7 @@ import mimetypes def clean_download(path: str): if os.path.exists(path): - LOGGER.info("Cleaning download: {}".format(path)) + LOGGER.info(f"Cleaning download: {path}") shutil.rmtree(path) diff --git a/bot/helper/gdriveTools.py b/bot/helper/gdriveTools.py index 830dc9c..163ef93 100644 --- a/bot/helper/gdriveTools.py +++ b/bot/helper/gdriveTools.py @@ -59,8 +59,8 @@ class GoogleDriveHelper: _list = get_download_status_list() index = get_download_index(_list, get_download(self.__listener.message.message_id).gid) self.__listener.onUploadStarted(_list, index) - file_dir = "{}{}".format(DOWNLOAD_DIR, self.__listener.message.message_id) - file_path = "{}/{}".format(file_dir, file_name) + file_dir = f"{DOWNLOAD_DIR}{self.__listener.message.message_id}" + file_path = f"{file_dir}/{file_name}" link = None LOGGER.info("Uploading File: " + file_name) if os.path.isfile(file_path): @@ -77,7 +77,7 @@ class GoogleDriveHelper: dir_id = self.create_directory(os.path.basename(os.path.abspath(file_name)), parent_id) self.upload_dir(file_path, dir_id) LOGGER.info("Uploaded To G-Drive: " + file_name) - link = "https://drive.google.com/folderview?id={}".format(dir_id) + link = f"https://drive.google.com/folderview?id={dir_id}" except Exception as e: LOGGER.error(str(e)) self.__listener.onUploadError(str(e), _list, index) @@ -146,7 +146,7 @@ class GoogleDriveHelper: def drive_list(self, fileName): msg = "" # Create Search Query for API request. - query = "'{}' in parents and (name contains '{}')".format(parent_id, fileName) + query = f"'{parent_id}' in parents and (name contains '{fileName}')" page_token = None while True: response = self.__service.files().list(q=query, @@ -155,13 +155,12 @@ class GoogleDriveHelper: pageToken=page_token).execute() for file in response.get('files', []): if file.get('mimeType') == "application/vnd.google-apps.folder": - msg += '⁍ {} (folder)'.format( - file.get('id'), file.get('name')) + "\n" + msg += f"⁍ {file.get('name')}" \ + f" (folder)" + "\n" # Detect Whether Current Entity is a Folder or File. else: - msg += '⁍ {}'.format(file.get('id'), - file.get( - 'name')) + "\n" + msg += f"⁍ {file.get('name')}" + "\n" page_token = response.get('nextPageToken', None) if page_token is None: break diff --git a/bot/list.py b/bot/list.py index 3b6079d..43a8cda 100644 --- a/bot/list.py +++ b/bot/list.py @@ -1,24 +1,26 @@ from telegram.ext import CommandHandler, run_async from telegram.error import BadRequest from bot.helper.gdriveTools import GoogleDriveHelper -from bot import LOGGER,dispatcher +from bot import LOGGER, dispatcher LOGGER.info('list.py') @run_async def list_drive(update, context): - message = update.message.text - search = message.replace('/list ', '') - LOGGER.info("Searching: "+search) - gdrive = GoogleDriveHelper(None) - msg = gdrive.drive_list(search) - if msg: - context.bot.send_message(chat_id=update.message.chat_id, reply_to_message_id=update.message.message_id, - text=msg,parse_mode='HTML') - else: - context.bot.send_message(chat_id=update.message.chat_id, reply_to_message_id=update.message.message_id, - text="No Results Found.") + message = update.message.text + search = message.replace('/list ', '') + LOGGER.info("Searching: " + search) + gdrive = GoogleDriveHelper(None) + msg = gdrive.drive_list(search) + if msg: + context.bot.send_message(chat_id=update.message.chat_id, reply_to_message_id=update.message.message_id, + text=msg, parse_mode='HTML') + + else: + context.bot.send_message(chat_id=update.message.chat_id, reply_to_message_id=update.message.message_id, + text="No Results Found.") + list_handler = CommandHandler('list', list_drive) -dispatcher.add_handler(list_handler) \ No newline at end of file +dispatcher.add_handler(list_handler) diff --git a/bot/mirror.py b/bot/mirror.py index 3d6ac72..8b8a966 100644 --- a/bot/mirror.py +++ b/bot/mirror.py @@ -27,14 +27,14 @@ class MirrorListener(listeners.MirrorListeners): raise KillThreadException('Message deleted. Terminate thread') def onDownloadComplete(self, progress_status_list, index: int): - LOGGER.info("Download completed: {}".format(progress_status_list[index].name())) + LOGGER.info(f"Download completed: {progress_status_list[index].name()}") gdrive = gdriveTools.GoogleDriveHelper(self) gdrive.upload(progress_status_list[index].name()) def onDownloadError(self, error, progress_status_list: list, index: int): LOGGER.error(error) - msg = "@{} your download has been cancelled due to: {}".format(self.message.from_user.username, error) + msg = f"@{self.message.from_user.username} your download has been cancelled due to: {error}" sendMessage(msg, self.context, self.update) del download_dict[self.message.message_id] fs_utils.clean_download(progress_status_list[index].path()) @@ -43,7 +43,7 @@ class MirrorListener(listeners.MirrorListeners): pass def onUploadComplete(self, link: str, progress_status_list: list, index: int): - msg = '{}'.format(link, progress_status_list[index].name()) + msg = f'{progress_status_list[index].name()}' del download_dict[self.message.message_id] try: deleteMessage(self.context, self.reply_message) @@ -77,10 +77,5 @@ def mirror(update, context): aria.add_download(link) -@run_async -def cancel_mirror(update, context): - pass - - mirror_handler = CommandHandler('mirror', mirror) dispatcher.add_handler(mirror_handler) diff --git a/bot/mirror_status.py b/bot/mirror_status.py index 41729f8..99a7eb1 100644 --- a/bot/mirror_status.py +++ b/bot/mirror_status.py @@ -3,7 +3,7 @@ from bot import dispatcher, status_reply_dict, DOWNLOAD_STATUS_UPDATE_INTERVAL from bot.helper.message_utils import * from time import sleep from bot.helper.bot_utils import get_readable_message - +from telegram.error import BadRequest @run_async def mirror_status(update: Update, context):