Conversation
111412e
to
03b94c4
Compare
03b94c4
to
1f2805a
Compare
while (1): | ||
while 1: | ||
choice = input() | ||
if choice == 'y' or choice == 'Y': | ||
if choice in ['y', 'Y']: | ||
msg = f'{lines}' | ||
break | ||
elif choice == 'n' or choice == 'N': | ||
elif choice in ['n', 'N']: | ||
break | ||
else: | ||
print("\n\n DO YOU WISH TO KEEP THE ABOVE DETAILS ???? y/n <=== this is option ..... OPEN YOUR EYES & READ...") | ||
num = int(input(" How Many Drive/Folder You Likes To Add : ")) | ||
count = 1 | ||
while count <= num : | ||
for count in range(1, num + 1): | ||
print(f"\n > DRIVE - {count}\n") | ||
name = input(" Enter Drive NAME (anything) : ") | ||
id = input(" Enter Drive ID : ") | ||
index = input(" Enter Drive INDEX URL (optional) : ") | ||
if not name or not id: | ||
print("\n\n ERROR : Dont leave the name/id without filling.") | ||
exit(1) | ||
exit(1) | ||
name=name.replace(" ", "_") | ||
if index: | ||
if index[-1] == "/": | ||
index = index[:-1] | ||
else: | ||
index = '' | ||
count+=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.
Lines 19-44
refactored with the following changes:
- Replace multiple comparisons of same variable with
in
operator (merge-comparisons
) - Replace while with for (
while-to-for
)
if credentials is None or not credentials.valid: | ||
if credentials and credentials.expired and credentials.refresh_token: | ||
credentials.refresh(Request()) | ||
if ( | ||
(credentials is None or not credentials.valid) | ||
and credentials | ||
and credentials.expired | ||
and credentials.refresh_token | ||
): | ||
credentials.refresh(Request()) |
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 12-14
refactored with the following changes:
- Merge nested if conditions (
merge-nested-ifs
)
if DRIVE_ID : | ||
pass | ||
else : | ||
if not DRIVE_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.
Lines 89-91
refactored with the following changes:
- Swap if/else to remove empty if body (
remove-pass-body
)
if parent_id != "root": | ||
response = self.__service.files().list(supportsTeamDrives=True, | ||
includeTeamDriveItems=True, | ||
teamDriveId=parent_id, | ||
q=query, | ||
corpora='drive', | ||
spaces='drive', | ||
pageSize=200, | ||
fields='files(id, name, mimeType, size, teamDriveId, parents)', | ||
orderBy='folder, modifiedTime desc').execute()["files"] | ||
else: | ||
response = self.__service.files().list(q=query + " and 'me' in owners", | ||
pageSize=200, | ||
spaces='drive', | ||
fields='files(id, name, mimeType, size, parents)', | ||
orderBy='folder, modifiedTime desc').execute()["files"] | ||
return response | ||
return ( | ||
self.__service.files() | ||
.list( | ||
supportsTeamDrives=True, | ||
includeTeamDriveItems=True, | ||
teamDriveId=parent_id, | ||
q=query, | ||
corpora='drive', | ||
spaces='drive', | ||
pageSize=200, | ||
fields='files(id, name, mimeType, size, teamDriveId, parents)', | ||
orderBy='folder, modifiedTime desc', | ||
) | ||
.execute()["files"] | ||
if parent_id != "root" | ||
else self.__service.files() | ||
.list( | ||
q=query + " and 'me' in owners", | ||
pageSize=200, | ||
spaces='drive', | ||
fields='files(id, name, mimeType, size, parents)', | ||
orderBy='folder, modifiedTime desc', | ||
) | ||
.execute()["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.drive_query
refactored with the following changes:
- Replace if statement with if expression (
assign-if-exp
) - Inline variable that is immediately returned (
inline-immediately-returned-variable
)
INDEX = -1 | ||
content_count = 0 | ||
add_title_msg = True | ||
for parent_id in DRIVE_ID : | ||
response = self.drive_query(parent_id, fileName) | ||
INDEX += 1 | ||
for INDEX, parent_id in enumerate(DRIVE_ID): | ||
response = self.drive_query(parent_id, fileName) | ||
if response: | ||
if add_title_msg == True: | ||
if add_title_msg: |
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:
- Replace manual loop counter with call to enumerate (
convert-to-enumerate
) - Simplify comparison to boolean (
simplify-boolean-comparison
) - Replace unneeded comprehension with generator (
comprehension-to-generator
)
elif reply_message is None: | ||
# Trying to authorize a chat | ||
chat_id = update.effective_chat.id | ||
if chat_id not in AUTHORIZED_CHATS: | ||
file.write(f'{chat_id}\n') | ||
AUTHORIZED_CHATS.add(chat_id) | ||
msg = 'Chat authorized' | ||
else: | ||
msg = 'Already authorized chat' | ||
else: | ||
if reply_message is None: | ||
# Trying to authorize a chat | ||
chat_id = update.effective_chat.id | ||
if chat_id not in AUTHORIZED_CHATS: | ||
file.write(f'{chat_id}\n') | ||
AUTHORIZED_CHATS.add(chat_id) | ||
msg = 'Chat authorized' | ||
else: | ||
msg = 'Already authorized chat' | ||
# Trying to authorize someone in specific | ||
user_id = reply_message.from_user.id | ||
if user_id not in AUTHORIZED_CHATS: | ||
file.write(f'{user_id}\n') | ||
AUTHORIZED_CHATS.add(user_id) | ||
msg = 'Person Authorized to use the bot!' | ||
else: | ||
# Trying to authorize someone in specific | ||
user_id = reply_message.from_user.id | ||
if user_id not in AUTHORIZED_CHATS: | ||
file.write(f'{user_id}\n') | ||
AUTHORIZED_CHATS.add(user_id) | ||
msg = 'Person Authorized to use the bot!' | ||
else: | ||
msg = 'Person already authorized' | ||
msg = 'Person already authorized' |
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 authorize
refactored with the following changes:
- Merge else clause's nested if statement into elif (
merge-else-if-into-elif
)
chat_id = int(message_[1]) | ||
if chat_id in AUTHORIZED_CHATS: | ||
AUTHORIZED_CHATS.remove(chat_id) | ||
msg = 'Chat unauthorized' | ||
else: | ||
msg = 'User already unauthorized' | ||
chat_id = int(message_[1]) | ||
if chat_id in AUTHORIZED_CHATS: | ||
AUTHORIZED_CHATS.remove(chat_id) | ||
msg = 'Chat unauthorized' | ||
else: | ||
msg = 'User already unauthorized' | ||
elif reply_message is None: | ||
# Trying to unauthorize a chat | ||
chat_id = update.effective_chat.id | ||
if chat_id in AUTHORIZED_CHATS: | ||
AUTHORIZED_CHATS.remove(chat_id) | ||
msg = 'Chat unauthorized' | ||
else: | ||
msg = 'Already unauthorized chat' | ||
else: | ||
if reply_message is None: | ||
# Trying to unauthorize a chat | ||
chat_id = update.effective_chat.id | ||
if chat_id in AUTHORIZED_CHATS: | ||
AUTHORIZED_CHATS.remove(chat_id) | ||
msg = 'Chat unauthorized' | ||
else: | ||
msg = 'Already unauthorized chat' | ||
# Trying to authorize someone in specific | ||
user_id = reply_message.from_user.id | ||
if user_id in AUTHORIZED_CHATS: | ||
AUTHORIZED_CHATS.remove(user_id) | ||
msg = 'Person unauthorized to use the bot!' | ||
else: | ||
# Trying to authorize someone in specific | ||
user_id = reply_message.from_user.id | ||
if user_id in AUTHORIZED_CHATS: | ||
AUTHORIZED_CHATS.remove(user_id) | ||
msg = 'Person unauthorized to use the bot!' | ||
else: | ||
msg = 'Person already unauthorized!' | ||
msg = 'Person already unauthorized!' |
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 unauthorize
refactored with the following changes:
- Merge else clause's nested if statement into elif (
merge-else-if-into-elif
)
users = '' | ||
for user in AUTHORIZED_CHATS : | ||
users += f"{user}\n" | ||
users = ''.join(f"{user}\n" for user in AUTHORIZED_CHATS) |
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 sendAuthChats
refactored with the following changes:
- Use str.join() instead of for loop (
use-join
)
Sourcery Code Quality Report✅ Merging this PR will increase code quality in the affected files by 1.30%.
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!