Skip to content
This repository has been archived by the owner on Jul 19, 2023. It is now read-only.

Sourcery refactored master branch #3

Merged
merged 2 commits into from Aug 31, 2021
Merged

Sourcery refactored master branch #3

merged 2 commits into from Aug 31, 2021

Conversation

sourcery-ai[bot]
Copy link
Contributor

@sourcery-ai sourcery-ai bot commented Aug 31, 2021

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:

git fetch origin sourcery/master
git merge --ff-only FETCH_HEAD
git reset HEAD^

Help us improve this pull request!

Comment on lines -19 to -44
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
Copy link
Contributor Author

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:

Comment on lines -12 to +18
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())
Copy link
Contributor Author

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:

if DRIVE_ID :
pass
else :
if not DRIVE_ID:
Copy link
Contributor Author

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:

bot/__main__.py Show resolved Hide resolved
Comment on lines -87 to +111
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"]
)
Copy link
Contributor Author

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:

Comment on lines -128 to +141
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:
Copy link
Contributor Author

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:

Comment on lines +23 to +40
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'
Copy link
Contributor Author

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:

Comment on lines -50 to +70
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!'
Copy link
Contributor Author

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:

Comment on lines -82 to +80
users = ''
for user in AUTHORIZED_CHATS :
users += f"{user}\n"
users = ''.join(f"{user}\n" for user in AUTHORIZED_CHATS)
Copy link
Contributor Author

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-ai
Copy link
Contributor Author

sourcery-ai bot commented Aug 31, 2021

Sourcery Code Quality Report

✅  Merging this PR will increase code quality in the affected files by 1.30%.

Quality metrics Before After Change
Complexity 16.21 🙂 15.06 🙂 -1.15 👍
Method Length 80.38 🙂 79.71 🙂 -0.67 👍
Working memory 11.45 😞 11.22 😞 -0.23 👍
Quality 48.41% 😞 49.71% 😞 1.30% 👍
Other metrics Before After Change
Lines 473 477 4
Changed files Quality Before Quality After Quality Change
driveid.py 35.08% 😞 40.49% 😞 5.41% 👍
generate_drive_token.py 60.29% 🙂 63.29% 🙂 3.00% 👍
bot/init.py 33.87% 😞 34.52% 😞 0.65% 👍
bot/main.py 90.71% ⭐ 90.74% ⭐ 0.03% 👍
bot/helper/drive_utils/gdriveTools.py 50.22% 🙂 50.48% 🙂 0.26% 👍
bot/modules/authorize.py 55.69% 🙂 57.46% 🙂 1.77% 👍

Here are some functions in these files that still need a tune-up:

File Function Complexity Length Working Memory Quality Recommendation
bot/helper/drive_utils/gdriveTools.py GoogleDriveHelper.drive_list 32 😞 306 ⛔ 19 ⛔ 16.59% ⛔ Refactor to reduce nesting. Try splitting into smaller methods. Extract out complex expressions
bot/modules/authorize.py authorize 12 🙂 133 😞 11 😞 51.41% 🙂 Try splitting into smaller methods. Extract out complex expressions
bot/modules/authorize.py unauthorize 13 🙂 122 😞 10 😞 53.76% 🙂 Try splitting into smaller methods. Extract out complex expressions
bot/helper/drive_utils/gdriveTools.py GoogleDriveHelper.get_recursive_list 3 ⭐ 100 🙂 13 😞 60.81% 🙂 Extract out complex expressions
bot/helper/drive_utils/gdriveTools.py GoogleDriveHelper.drive_query 1 ⭐ 68 🙂 16 ⛔ 63.67% 🙂 Extract out complex expressions

Legend and Explanation

The emojis denote the absolute quality of the code:

  • ⭐ excellent
  • 🙂 good
  • 😞 poor
  • ⛔ very poor

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!

@breakdowns breakdowns merged commit ff9e861 into master Aug 31, 2021
@breakdowns breakdowns deleted the sourcery/master branch September 2, 2021 00:18
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant