-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Sourcery refactored master branch #1
Conversation
8523247
to
a080539
Compare
else: | ||
if not self.__is_cancelled: | ||
self.__onDownloadError('Internal error occurred') | ||
elif not self.__is_cancelled: | ||
self.__onDownloadError('Internal error occurred') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function TelegramDownloadHelper.__download
refactored with the following changes:
- Merge else clause's nested if statement into elif (
merge-else-if-into-elif
)
status = MirrorStatus.STATUS_WAITING | ||
return MirrorStatus.STATUS_WAITING | ||
elif download.is_paused: | ||
status = MirrorStatus.STATUS_CANCELLED | ||
return MirrorStatus.STATUS_CANCELLED | ||
elif download.has_failed: | ||
status = MirrorStatus.STATUS_FAILED | ||
return MirrorStatus.STATUS_FAILED | ||
else: | ||
status = MirrorStatus.STATUS_DOWNLOADING | ||
return status | ||
return MirrorStatus.STATUS_DOWNLOADING |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function AriaDownloadStatus.status
refactored with the following changes:
- Lift return into if (
lift-return-into-if
)
if reason == 'userRateLimitExceeded' or reason == 'dailyLimitExceeded': | ||
if USE_SERVICE_ACCOUNTS: | ||
self.switchServiceAccount() | ||
LOGGER.info(f"Got: {reason}, Trying Again.") | ||
return self.upload_file(file_path, file_name, mime_type, parent_id) | ||
else: | ||
if reason not in [ | ||
'userRateLimitExceeded', | ||
'dailyLimitExceeded', | ||
]: | ||
raise err | ||
if USE_SERVICE_ACCOUNTS: | ||
self.switchServiceAccount() | ||
LOGGER.info(f"Got: {reason}, Trying Again.") | ||
return self.upload_file(file_path, file_name, mime_type, parent_id) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function GoogleDriveHelper.upload_file
refactored with the following changes:
- Replace multiple comparisons of same variable with
in
operator (merge-comparisons
) - Swap if/else branches (
swap-if-else-branches
) - Remove unnecessary else after guard condition (
remove-unnecessary-else
)
res = self.__service.files().copy(supportsAllDrives=True,fileId=file_id,body=body).execute() | ||
return res | ||
return ( | ||
self.__service.files() | ||
.copy(supportsAllDrives=True, fileId=file_id, body=body) | ||
.execute() | ||
) | ||
|
||
except HttpError as err: | ||
if err.resp.get('content-type', '').startswith('application/json'): | ||
reason = json.loads(err.content).get('error').get('errors')[0].get('reason') | ||
if reason == 'userRateLimitExceeded' or reason == 'dailyLimitExceeded': | ||
if USE_SERVICE_ACCOUNTS: | ||
self.switchServiceAccount() | ||
LOGGER.info(f"Got: {reason}, Trying Again.") | ||
return self.copyFile(file_id,dest_id) | ||
else: | ||
if reason not in ['userRateLimitExceeded', 'dailyLimitExceeded']: | ||
raise err | ||
|
||
if USE_SERVICE_ACCOUNTS: | ||
self.switchServiceAccount() | ||
LOGGER.info(f"Got: {reason}, Trying Again.") | ||
return self.copyFile(file_id,dest_id) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function GoogleDriveHelper.copyFile
refactored with the following changes:
- Replace multiple comparisons of same variable with
in
operator (merge-comparisons
) - Inline variable that is immediately returned (
inline-immediately-returned-variable
) - Swap if/else branches (
swap-if-else-branches
) - Remove unnecessary else after guard condition (
remove-unnecessary-else
)
if response["files"]: | ||
content_count = 0 | ||
self.telegraph_content = [] | ||
self.path = [] | ||
msg += f'<h4>Results : {fileName}</h4><br>@LoaderXbot #ProjektX<br><br>' | ||
if not response["files"]: | ||
return "No Result Found :(", None | ||
|
||
for file in response.get('files', []): | ||
if file.get('mimeType') == "application/vnd.google-apps.folder": # Detect Whether Current Entity is a Folder or File. | ||
msg += f"⁍<code>{file.get('name')}<br>(folder📁)</code><br>" \ | ||
f"<b><a href='https://drive.google.com/drive/folders/{file.get('id')}'>Drive Link</a></b>" | ||
if INDEX_URL is not None: | ||
url_path = requests.utils.quote(f'{file.get("name")}') | ||
url = f'{INDEX_URL}/{url_path}/' | ||
msg += f' <b>| <a href="{url}">Index Link</a></b>' | ||
content_count = 0 | ||
self.telegraph_content = [] | ||
self.path = [] | ||
msg += f'<h4>Results : {fileName}</h4><br>@LoaderXbot #ProjektX<br><br>' | ||
|
||
else: | ||
msg += f"⁍<code>{file.get('name')}<br>({get_readable_file_size(int(file.get('size')))})📄</code><br>" \ | ||
f"<b><a href='https://drive.google.com/uc?id={file.get('id')}&export=download'>Drive Link</a></b>" | ||
if INDEX_URL is not None: | ||
url_path = requests.utils.quote(f'{file.get("name")}') | ||
url = f'{INDEX_URL}/{url_path}' | ||
msg += f' <b>| <a href="{url}">Index Link</a></b>' | ||
msg += '<br><br>' | ||
content_count += 1 | ||
if content_count == TELEGRAPHLIMIT : | ||
self.telegraph_content.append(msg) | ||
msg = "" | ||
content_count = 0 | ||
|
||
if msg != '': | ||
for file in response.get('files', []): | ||
if file.get('mimeType') == "application/vnd.google-apps.folder": # Detect Whether Current Entity is a Folder or File. | ||
msg += f"⁍<code>{file.get('name')}<br>(folder📁)</code><br>" \ | ||
f"<b><a href='https://drive.google.com/drive/folders/{file.get('id')}'>Drive Link</a></b>" | ||
if INDEX_URL is not None: | ||
url_path = requests.utils.quote(f'{file.get("name")}') | ||
url = f'{INDEX_URL}/{url_path}/' | ||
msg += f' <b>| <a href="{url}">Index Link</a></b>' | ||
|
||
else: | ||
msg += f"⁍<code>{file.get('name')}<br>({get_readable_file_size(int(file.get('size')))})📄</code><br>" \ | ||
f"<b><a href='https://drive.google.com/uc?id={file.get('id')}&export=download'>Drive Link</a></b>" | ||
if INDEX_URL is not None: | ||
url_path = requests.utils.quote(f'{file.get("name")}') | ||
url = f'{INDEX_URL}/{url_path}' | ||
msg += f' <b>| <a href="{url}">Index Link</a></b>' | ||
msg += '<br><br>' | ||
content_count += 1 | ||
if content_count == TELEGRAPHLIMIT : | ||
self.telegraph_content.append(msg) | ||
msg = "" | ||
content_count = 0 | ||
|
||
for content in self.telegraph_content : | ||
self.path.append(telegra_ph.create_page(title = 'LoaderX', | ||
html_content=content )['path']) | ||
if msg != '': | ||
self.telegraph_content.append(msg) | ||
|
||
self.num_of_path = len(self.path) | ||
if self.num_of_path > 1: | ||
self.edit_telegraph() | ||
for content in self.telegraph_content : | ||
self.path.append(telegra_ph.create_page(title = 'LoaderX', | ||
html_content=content )['path']) | ||
|
||
msg = f"<b>Search Results For {fileName} 👇</b>" | ||
buttons = button_builder.ButtonMaker() | ||
buttons.buildbutton("HERE", f"https://telegra.ph/{self.path[0]}") | ||
self.num_of_path = len(self.path) | ||
if self.num_of_path > 1: | ||
self.edit_telegraph() | ||
|
||
return msg, InlineKeyboardMarkup(buttons.build_menu(1)) | ||
msg = f"<b>Search Results For {fileName} 👇</b>" | ||
buttons = button_builder.ButtonMaker() | ||
buttons.buildbutton("HERE", f"https://telegra.ph/{self.path[0]}") | ||
|
||
else : | ||
return "No Result Found :(", None | ||
return msg, InlineKeyboardMarkup(buttons.build_menu(1)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function GoogleDriveHelper.drive_list
refactored with the following changes:
- Swap if/else branches (
swap-if-else-branches
) - Remove unnecessary else after guard condition (
remove-unnecessary-else
)
if dlDetails.status() == MirrorStatus.STATUS_DOWNLOADING \ | ||
or dlDetails.status() == MirrorStatus.STATUS_WAITING: | ||
if dlDetails.status() in [ | ||
MirrorStatus.STATUS_DOWNLOADING, | ||
MirrorStatus.STATUS_WAITING, | ||
]: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function cancel_all
refactored with the following changes:
- Replace multiple comparisons of same variable with
in
operator (merge-comparisons
)
LOGGER.info(msg_args[1]) | ||
LOGGER.info(link) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function deletefile
refactored with the following changes:
- Use previously assigned local variable (
use-assigned-variable
)
@@ -116,7 +116,6 @@ def onDownloadError(self, error): | |||
LOGGER.info(str(download_dict)) | |||
except Exception as e: | |||
LOGGER.error(str(e)) | |||
pass |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function MirrorListener.onDownloadError
refactored with the following changes:
- Remove redundant pass statement (
remove-redundant-pass
)
if len(link) == 0: | ||
if file is not None: | ||
if file.mime_type != "application/x-bittorrent": | ||
listener = MirrorListener(bot, update, isTar, tag) | ||
tg_downloader = TelegramDownloadHelper(listener) | ||
tg_downloader.add_download(reply_to, f'{DOWNLOAD_DIR}{listener.uid}/') | ||
sendStatusMessage(update, bot) | ||
if len(Interval) == 0: | ||
Interval.append(setInterval(DOWNLOAD_STATUS_UPDATE_INTERVAL, update_all_messages)) | ||
return | ||
else: | ||
link = file.get_file().file_path | ||
if len(link) == 0 and file is not None: | ||
if file.mime_type != "application/x-bittorrent": | ||
listener = MirrorListener(bot, update, isTar, tag) | ||
tg_downloader = TelegramDownloadHelper(listener) | ||
tg_downloader.add_download(reply_to, f'{DOWNLOAD_DIR}{listener.uid}/') | ||
sendStatusMessage(update, bot) | ||
if len(Interval) == 0: | ||
Interval.append(setInterval(DOWNLOAD_STATUS_UPDATE_INTERVAL, update_all_messages)) | ||
return | ||
else: | ||
link = file.get_file().file_path |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function _mirror
refactored with the following changes:
- Merge nested if conditions (
merge-nested-ifs
)
if reply_to is not None: | ||
tag = reply_to.from_user.username | ||
else: | ||
tag = None | ||
|
||
tag = reply_to.from_user.username if reply_to is not None else None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function _watch
refactored with the following changes:
- Replace if statement with if expression (
assign-if-exp
)
a080539
to
94b5423
Compare
Sourcery Code Quality Report✅ Merging this PR will increase code quality in the affected files by 1.34%.
Here are some functions in these files that still need a tune-up:
Legend and ExplanationThe emojis denote the absolute quality of the code:
The 👍 and 👎 indicate whether the quality has improved or gotten worse with this pull request. Please see our documentation here for details on how these metrics are calculated. We are actively working on this report - lots more documentation and extra metrics to come! Help us improve this quality report! |
for i in range(count): | ||
for _ in range(count): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function _create_accounts
refactored with the following changes:
- Replace unused for index with underscore (
for-index-underscore
)
for i in range(count): | ||
for _ in range(count): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function _create_accounts._create_remaining_accounts._create_projects
refactored with the following changes:
- Replace unused for index with underscore (
for-index-underscore
)
index = 0 | ||
for j in current_key_dump: | ||
for index, j in enumerate(current_key_dump): | ||
with open(f'{path}/{index}.json', 'w+') as f: | ||
f.write(j[1]) | ||
index += 1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function _create_accounts._create_remaining_accounts._list_sas._create_sa_keys
refactored with the following changes:
- Replace manual loop counter with call to enumerate (
convert-to-enumerate
)
while projs == None: | ||
while projs is None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function _create_accounts._create_remaining_accounts._list_sas._delete_sas.serviceaccountfactory
refactored with the following changes:
- Swap if/else to remove empty if body (
remove-pass-body
) - Use x is None rather than x == None (
none-compare
) - Merge append into list declaration (
merge-list-append
)
i = 0 | ||
print('Select a credentials file below.') | ||
inp_options = [str(i) for i in list(range(1, len(options) + 1))] + options | ||
while i < len(options): | ||
for i in range(len(options)): | ||
print(' %d) %s' % (i + 1, options[i])) | ||
i += 1 | ||
inp = None | ||
while True: | ||
inp = input('> ') | ||
if inp in inp_options: | ||
break | ||
if inp in options: | ||
args.credentials = inp | ||
else: | ||
args.credentials = options[int(inp) - 1] | ||
args.credentials = inp if inp in options else options[int(inp) - 1] | ||
print('Use --credentials %s next time to use this credentials file.' % args.credentials) | ||
if args.quick_setup: | ||
opt = '*' | ||
if args.new_only: | ||
opt = '~' | ||
opt = '~' if args.new_only else '*' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lines 312-331
refactored with the following changes:
- Replace if statement with if expression (
assign-if-exp
) - Replace while with for (
while-to-for
)
bot/helper/ext_utils/db_handler.py
Outdated
if self.err : | ||
if self.err: | ||
return "There's some error check log for details" | ||
else: | ||
sql = 'UPDATE users SET sudo = FALSE where uid = {};'.format(chat_id) | ||
self.cur.execute(sql) | ||
self.conn.commit() | ||
self.disconnect() | ||
SUDO_USERS.remove(chat_id) | ||
return 'Successfully removed from Sudo' No newline at end of file | ||
sql = 'UPDATE users SET sudo = FALSE where uid = {};'.format(chat_id) | ||
self.cur.execute(sql) | ||
self.conn.commit() | ||
self.disconnect() | ||
SUDO_USERS.remove(chat_id) | ||
return 'Successfully removed from Sudo' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function DbManger.db_rmsudo
refactored with the following changes:
- Remove unnecessary else after guard condition (
remove-unnecessary-else
)
mime_type = mime_type if mime_type else "text/plain" | ||
mime_type = mime_type or "text/plain" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function get_mime_type
refactored with the following changes:
- Simplify if expression by using or (
or-if-exp-identity
)
else: | ||
if dl: threading.Thread(target=dl.getListener().onDownloadComplete).start() | ||
elif dl: threading.Thread(target=dl.getListener().onDownloadComplete).start() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function AriaDownloadHelper.__onDownloadComplete
refactored with the following changes:
- Merge else clause's nested if statement into elif (
merge-else-if-into-elif
)
reply = "`No Yandex.Disk links found`\n" | ||
return reply | ||
return "`No Yandex.Disk links found`\n" | ||
api = 'https://cloud-api.yandex.net/v1/disk/public/resources/download?public_key={}' | ||
try: | ||
dl_url = requests.get(api.format(link)).json()['href'] | ||
return dl_url | ||
return requests.get(api.format(link)).json()['href'] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function yandex_disk
refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable
)
dl_url = data['download'] | ||
return dl_url | ||
return data['download'] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function cm_ru
refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable
)
dl_url = info.get('href') | ||
return dl_url | ||
return info.get('href') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function mediafire
refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable
)
dl_url = download.headers["location"] | ||
return dl_url | ||
return download.headers["location"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function github
refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable
)
else: | ||
if not self.__is_cancelled: | ||
self.__onDownloadError('Internal error occurred') | ||
elif not self.__is_cancelled: | ||
self.__onDownloadError('Internal error occurred') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function TelegramDownloadHelper.__download
refactored with the following changes:
- Merge else clause's nested if statement into elif (
merge-else-if-into-elif
)
status = MirrorStatus.STATUS_WAITING | ||
return MirrorStatus.STATUS_WAITING | ||
elif download.is_paused: | ||
status = MirrorStatus.STATUS_CANCELLED | ||
return MirrorStatus.STATUS_CANCELLED | ||
elif download.has_failed: | ||
status = MirrorStatus.STATUS_FAILED | ||
return MirrorStatus.STATUS_FAILED | ||
else: | ||
status = MirrorStatus.STATUS_DOWNLOADING | ||
return status | ||
return MirrorStatus.STATUS_DOWNLOADING |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function AriaDownloadStatus.status
refactored with the following changes:
- Lift return into if (
lift-return-into-if
)
if reason == 'userRateLimitExceeded' or reason == 'dailyLimitExceeded': | ||
if USE_SERVICE_ACCOUNTS: | ||
self.switchServiceAccount() | ||
LOGGER.info(f"Got: {reason}, Trying Again.") | ||
return self.upload_file(file_path, file_name, mime_type, parent_id) | ||
else: | ||
if reason not in [ | ||
'userRateLimitExceeded', | ||
'dailyLimitExceeded', | ||
]: | ||
raise err | ||
if USE_SERVICE_ACCOUNTS: | ||
self.switchServiceAccount() | ||
LOGGER.info(f"Got: {reason}, Trying Again.") | ||
return self.upload_file(file_path, file_name, mime_type, parent_id) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function GoogleDriveHelper.upload_file
refactored with the following changes:
- Replace multiple comparisons of same variable with
in
operator (merge-comparisons
) - Swap if/else branches (
swap-if-else-branches
) - Remove unnecessary else after guard condition (
remove-unnecessary-else
)
if dlDetails.status() == MirrorStatus.STATUS_DOWNLOADING \ | ||
or dlDetails.status() == MirrorStatus.STATUS_WAITING: | ||
if dlDetails.status() in [ | ||
MirrorStatus.STATUS_DOWNLOADING, | ||
MirrorStatus.STATUS_WAITING, | ||
]: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function cancel_all
refactored with the following changes:
- Replace multiple comparisons of same variable with
in
operator (merge-comparisons
)
LOGGER.info(msg_args[1]) | ||
LOGGER.info(link) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function deletefile
refactored with the following changes:
- Use previously assigned local variable (
use-assigned-variable
)
@@ -116,7 +116,6 @@ def onDownloadError(self, error): | |||
LOGGER.info(str(download_dict)) | |||
except Exception as e: | |||
LOGGER.error(str(e)) | |||
pass |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function MirrorListener.onDownloadError
refactored with the following changes:
- Remove redundant pass statement (
remove-redundant-pass
)
if len(link) == 0: | ||
if file is not None: | ||
if file.mime_type != "application/x-bittorrent": | ||
listener = MirrorListener(bot, update, isTar, tag) | ||
tg_downloader = TelegramDownloadHelper(listener) | ||
tg_downloader.add_download(reply_to, f'{DOWNLOAD_DIR}{listener.uid}/') | ||
sendStatusMessage(update, bot) | ||
if len(Interval) == 0: | ||
Interval.append(setInterval(DOWNLOAD_STATUS_UPDATE_INTERVAL, update_all_messages)) | ||
return | ||
else: | ||
link = file.get_file().file_path | ||
if len(link) == 0 and file is not None: | ||
if file.mime_type != "application/x-bittorrent": | ||
listener = MirrorListener(bot, update, isTar, tag) | ||
tg_downloader = TelegramDownloadHelper(listener) | ||
tg_downloader.add_download(reply_to, f'{DOWNLOAD_DIR}{listener.uid}/') | ||
sendStatusMessage(update, bot) | ||
if len(Interval) == 0: | ||
Interval.append(setInterval(DOWNLOAD_STATUS_UPDATE_INTERVAL, update_all_messages)) | ||
return | ||
else: | ||
link = file.get_file().file_path |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function _mirror
refactored with the following changes:
- Merge nested if conditions (
merge-nested-ifs
)
if reply_to is not None: | ||
tag = reply_to.from_user.username | ||
else: | ||
tag = None | ||
|
||
tag = reply_to.from_user.username if reply_to is not None else None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function _watch
refactored with the following changes:
- Replace if statement with if expression (
assign-if-exp
)
Branch
master
refactored by Sourcery.If you're happy with these changes, merge this Pull Request using the Squash and merge strategy.
See our documentation here.
Run Sourcery locally
Reduce the feedback loop during development by using the Sourcery editor plugin:
Review changes via command line
To manually merge these changes, make sure you're on the
master
branch, then run:Help us improve this pull request!