-
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
base: master
Are you sure you want to change the base?
Conversation
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.
Due to GitHub API limits, only the first 60 comments can be shown.
aa = glob.glob('%s/*.json' % acc_dir) | ||
aa = glob.glob(f'{acc_dir}/*.json') |
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 60-60
refactored with the following changes:
- Replace interpolated string formatting with f-string (
replace-interpolation-with-fstring
)
batch.add(service.projects().serviceAccounts().create(name='projects/' + project, body={'accountId': aid, | ||
'serviceAccount': { | ||
'displayName': aid}})) | ||
batch.add( | ||
service.projects() | ||
.serviceAccounts() | ||
.create( | ||
name=f'projects/{project}', | ||
body={ | ||
'accountId': aid, | ||
'serviceAccount': {'displayName': aid}, | ||
}, | ||
) | ||
) | ||
|
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:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation
)
print('Creating accounts in %s' % project) | ||
print(f'Creating accounts in {project}') |
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_remaining_accounts
refactored with the following changes:
- Replace interpolated string formatting with f-string (
replace-interpolation-with-fstring
)
print(str(exception)) | ||
print(exception) |
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 _def_batch_resp
refactored with the following changes:
- Remove unnecessary call to
str()
withinprint()
(remove-str-from-print
)
print(str(exception)) | ||
print(exception) |
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 _pc_resp
refactored with the following changes:
- Remove unnecessary call to
str()
withinprint()
(remove-str-from-print
)
if MEGAREST is True: | ||
if MEGAREST: |
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 309-638
refactored with the following changes:
- Replaces an empty collection equality with a boolean operation. (
simplify-empty-collection-comparison
) - Simplify comparison to boolean (
simplify-boolean-comparison
) - Simplify comparison to string length (
simplify-str-len-comparison
) - Remove unnecessary else after guard condition (
remove-unnecessary-else
)
Thread(target=auto_delete_message, args=(context.bot, update.message, message)).start() | ||
return | ||
else: | ||
message = sendMarkup( | ||
f'Dear {uname},\n\nIf You Want To Use Me, You Have To Join @{CHANNEL_USERNAME}\n\n', | ||
context.bot, update, reply_markup) | ||
Thread(target=auto_delete_message, args=(context.bot, update.message, message)).start() | ||
return | ||
|
||
Thread(target=auto_delete_message, args=(context.bot, update.message, message)).start() | ||
return |
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 start
refactored with the following changes:
- Hoist repeated code outside conditional statement (
hoist-statement-from-if
)
text = "<b>Bot Restarted!</b>" | ||
message = bot.sendMessage(chat_id=OWNER_ID, text=text, parse_mode=ParseMode.HTML) | ||
if AUTHORIZED_CHATS: | ||
text = "<b>Bot Restarted!</b>" | ||
message = bot.sendMessage(chat_id=OWNER_ID, text=text, parse_mode=ParseMode.HTML) |
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 main
refactored with the following changes:
- Move assignments closer to their usage (
move-assign
)
rows = self.cur.fetchall() #returns a list ==> (uid, sudo, auth, media, doc, thumb) | ||
if rows: | ||
if rows := self.cur.fetchall(): |
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_load
refactored with the following changes:
- Use named expression to simplify assignment and conditional (
use-named-expression
)
This removes the following comments ( why? ):
#returns a list ==> (uid, sudo, auth, media, doc, thumb)
#returns a list ==> (name, feed_link, last_link, last_title, filters)
sql = 'INSERT INTO users (uid, auth) VALUES ({}, TRUE)'.format(chat_id) | ||
sql = f'INSERT INTO users (uid, auth) VALUES ({chat_id}, TRUE)' | ||
else: | ||
sql = 'UPDATE users SET auth = TRUE WHERE uid = {}'.format(chat_id) | ||
sql = f'UPDATE users SET auth = TRUE WHERE uid = {chat_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 DbManger.user_auth
refactored with the following changes:
- Replace call to format with f-string. (
use-fstring-for-formatting
)
sql = 'UPDATE users SET auth = FALSE WHERE uid = {}'.format(chat_id) | ||
sql = f'UPDATE users SET auth = FALSE WHERE uid = {chat_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 DbManger.user_unauth
refactored with the following changes:
- Replace call to format with f-string. (
use-fstring-for-formatting
)
sql = 'INSERT INTO users (uid, leechlog) VALUES ({}, TRUE)'.format(chat_id) | ||
sql = f'INSERT INTO users (uid, leechlog) VALUES ({chat_id}, TRUE)' | ||
else: | ||
sql = 'UPDATE users SET leechlog = TRUE WHERE uid = {}'.format(chat_id) | ||
sql = f'UPDATE users SET leechlog = TRUE WHERE uid = {chat_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 DbManger.addleech_log
refactored with the following changes:
- Replace call to format with f-string. (
use-fstring-for-formatting
)
sql = 'UPDATE users SET leechlog = FALSE WHERE uid = {}'.format(chat_id) | ||
sql = f'UPDATE users SET leechlog = FALSE WHERE uid = {chat_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 DbManger.rmleech_log
refactored with the following changes:
- Replace call to format with f-string. (
use-fstring-for-formatting
)
sql = 'INSERT INTO users (uid, leechlogalt) VALUES ({}, TRUE)'.format(chat_id) | ||
sql = f'INSERT INTO users (uid, leechlogalt) VALUES ({chat_id}, TRUE)' | ||
else: | ||
sql = 'UPDATE users SET leechlogalt = TRUE WHERE uid = {}'.format(chat_id) | ||
sql = f'UPDATE users SET leechlogalt = TRUE WHERE uid = {chat_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 DbManger.addleech_log_alt
refactored with the following changes:
- Replace call to format with f-string. (
use-fstring-for-formatting
)
sql = 'UPDATE users SET leechlogalt = FALSE WHERE uid = {}'.format(chat_id) | ||
sql = f'UPDATE users SET leechlogalt = FALSE WHERE uid = {chat_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 DbManger.rmleech_log_alt
refactored with the following changes:
- Replace call to format with f-string. (
use-fstring-for-formatting
)
if STOP_DUPLICATE and dl is not None and not dl.getListener().isLeech: | ||
LOGGER.info('Checking File/Folder if already in Drive...') | ||
sname = download.name | ||
if dl.getListener().isZip: | ||
sname = sname + ".zip" | ||
elif dl.getListener().extract: | ||
try: | ||
sname = get_base_name(sname) | ||
except: | ||
sname = None | ||
if sname is not None: | ||
smsg, button = GoogleDriveHelper().drive_list(sname, True) | ||
if smsg: | ||
dl.getListener().onDownloadError('File/Folder already available in Drive.\n\n') | ||
api.remove([download], force=True, files=True) | ||
return sendMarkup("Here are the search results:", dl.getListener().bot, dl.getListener().update, button) | ||
if dl is not None and (ZIP_UNZIP_LIMIT is not None or TORRENT_DIRECT_LIMIT is not None): | ||
sleep(1) | ||
limit = None | ||
if ZIP_UNZIP_LIMIT is not None and (dl.getListener().isZip or dl.getListener().extract): | ||
mssg = f'Zip/Unzip limit is {ZIP_UNZIP_LIMIT}GB' | ||
limit = ZIP_UNZIP_LIMIT | ||
elif TORRENT_DIRECT_LIMIT is not None: | ||
mssg = f'Torrent/Direct limit is {TORRENT_DIRECT_LIMIT}GB' | ||
limit = TORRENT_DIRECT_LIMIT | ||
if limit is not None: | ||
LOGGER.info('Checking File/Folder Size...') | ||
size = api.get_download(gid).total_length | ||
if size > limit * 1024**3: | ||
dl.getListener().onDownloadError(f'{mssg}.\nYour File/Folder size is {get_readable_file_size(size)}') | ||
return api.remove([download], force=True, files=True) | ||
if STOP_DUPLICATE and dl is not None and not dl.getListener().isLeech: | ||
LOGGER.info('Checking File/Folder if already in Drive...') | ||
sname = download.name | ||
if dl.getListener().isZip: | ||
sname = f"{sname}.zip" | ||
elif dl.getListener().extract: | ||
try: | ||
sname = get_base_name(sname) | ||
except: | ||
sname = None | ||
if sname is not None: | ||
smsg, button = GoogleDriveHelper().drive_list(sname, True) | ||
if smsg: | ||
dl.getListener().onDownloadError('File/Folder already available in Drive.\n\n') | ||
api.remove([download], force=True, files=True) | ||
return sendMarkup("Here are the search results:", dl.getListener().bot, dl.getListener().update, button) | ||
if dl is not None and (ZIP_UNZIP_LIMIT is not None or TORRENT_DIRECT_LIMIT is not None): | ||
sleep(1) | ||
limit = None | ||
if ZIP_UNZIP_LIMIT is not None and (dl.getListener().isZip or dl.getListener().extract): | ||
mssg = f'Zip/Unzip limit is {ZIP_UNZIP_LIMIT}GB' | ||
limit = ZIP_UNZIP_LIMIT | ||
elif TORRENT_DIRECT_LIMIT is not None: | ||
mssg = f'Torrent/Direct limit is {TORRENT_DIRECT_LIMIT}GB' | ||
limit = TORRENT_DIRECT_LIMIT | ||
if limit is not None: | ||
LOGGER.info('Checking File/Folder Size...') | ||
size = api.get_download(gid).total_length | ||
if size > limit * 1024**3: | ||
dl.getListener().onDownloadError(f'{mssg}.\nYour File/Folder size is {get_readable_file_size(size)}') | ||
return api.remove([download], force=True, files=True) |
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 __onDownloadStarted
refactored with the following changes:
- Hoist conditional out of nested conditional (
hoist-if-from-if
) - Use f-string instead of string concatenation (
use-fstring-for-concatenation
)
dl = getDownloadByGid(gid) | ||
if dl: | ||
if dl := getDownloadByGid(gid): |
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 __onDownloadStopped
refactored with the following changes:
- Use named expression to simplify assignment and conditional (
use-named-expression
)
file_link = 'https://uptobox.com/api/link?token=%s&file_code=%s' % (UPTOBOX_TOKEN, file_id) | ||
file_link = f'https://uptobox.com/api/link?token={UPTOBOX_TOKEN}&file_code={file_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 uptobox
refactored with the following changes:
- Replace interpolated string formatting with f-string (
replace-interpolation-with-fstring
)
raise DirectDownloadLinkException("ERROR: Cant't download due {}.".format(resp["message"])) | ||
raise DirectDownloadLinkException( | ||
f"""ERROR: Cant't download due {resp["message"]}.""" | ||
) |
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 pixeldrain
refactored with the following changes:
- Replace call to format with f-string. (
use-fstring-for-formatting
)
numbers = [int(word) for word in str(str_2).split() if word.isdigit()] | ||
if not numbers: | ||
raise DirectDownloadLinkException("ERROR: 1fichier is on a limit. Please wait a few minutes/hour.") | ||
else: | ||
if numbers := [ | ||
int(word) for word in str(str_2).split() if word.isdigit() | ||
]: | ||
raise DirectDownloadLinkException(f"ERROR: 1fichier is on a limit. Please wait {numbers[0]} minute.") |
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 fichier
refactored with the following changes:
- Use named expression to simplify assignment and conditional (
use-named-expression
) - Swap if/else branches (
swap-if-else-branches
)
mainOptions = str(re.search(r'viewerOptions\'\,\ (.*?)\)\;', pageSource).group(1)) | ||
mainOptions = str(re.search(r'viewerOptions\'\,\ (.*?)\)\;', pageSource)[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 solidfiles
refactored with the following changes:
- Replace m.group(x) with m[x] for re.Match objects (
use-getitem-for-re-match-groups
)
gname = name + ".zip" | ||
gname = f"{name}.zip" |
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 add_gd_download
refactored with the following changes:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation
)
if (dlInfo['state'] == constants.State.TYPE_STATE_COMPLETED or dlInfo[ | ||
'state'] == constants.State.TYPE_STATE_CANCELED or dlInfo[ | ||
'state'] == constants.State.TYPE_STATE_FAILED) and self.__periodic is not None: | ||
if ( | ||
dlInfo['state'] | ||
in [ | ||
constants.State.TYPE_STATE_COMPLETED, | ||
constants.State.TYPE_STATE_CANCELED, | ||
constants.State.TYPE_STATE_FAILED, | ||
] | ||
and self.__periodic is not 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 MegaDownloadeHelper.__onInterval
refactored with the following changes:
- Replace multiple comparisons of same variable with
in
operator (merge-comparisons
)
self.listener.onDownloadError("RequestTempError: " + error.toString()) | ||
self.listener.onDownloadError(f"RequestTempError: {error.toString()}") |
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 MegaAppListener.onRequestTemporaryError
refactored with the following changes:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation
)
mname = mname + ".zip" | ||
mname = f"{mname}.zip" |
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 add_mega_download
refactored with the following changes:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation
)
@@ -759,7 +755,6 @@ def count(self, link): | |||
msg += f'\n\n<b>Size: </b>{get_readable_file_size(self.__total_bytes)}' | |||
msg += '\n\n<b>Type: </b>Folder' | |||
msg += f'\n<b>SubFolders: </b>{self.__total_folders}' | |||
msg += f'\n<b>Files: </b>{self.__total_files}' |
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.count
refactored with the following changes:
- Hoist repeated code outside conditional statement (
hoist-statement-from-if
) - Remove unnecessary casts to int, str, float or bool (
remove-unnecessary-cast
)
if "File not found" in str(err): | ||
if "File not found" in err: |
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.helper
refactored with the following changes:
- Remove unnecessary casts to int, str, float or bool (
remove-unnecessary-cast
)
if "downloadQuotaExceeded" in str(err): | ||
if "downloadQuotaExceeded" in err: | ||
err = "Download Quota Exceeded." | ||
elif "File not found" in str(err): | ||
elif "File not found" in err: |
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.download
refactored with the following changes:
- Remove unnecessary casts to int, str, float or bool (
remove-unnecessary-cast
)
path += folder_name + '/' | ||
path += f'{folder_name}/' |
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.__download_folder
refactored with the following changes:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation
)
fh = FileIO('{}{}'.format(path, filename), 'wb') | ||
fh = FileIO(f'{path}{filename}', 'wb') |
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.__download_file
refactored with the following changes:
- Replace call to format with f-string. (
use-fstring-for-formatting
)
Sourcery Code Quality Report✅ Merging this PR will increase code quality in the affected files by 0.38%.
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! |
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!