Skip to content

Conversation

@sourcery-ai
Copy link

@sourcery-ai sourcery-ai bot commented Jan 3, 2022

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!

@sourcery-ai sourcery-ai bot requested a review from Ahmed123br January 3, 2022 13:04
process = psutil.Process(os.getpid())
mem = process.get_memory_info()[0] / float(2 ** 20)
return mem
return process.get_memory_info()[0] / float(2 ** 20)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function memory_usage_psutil refactored with the following changes:

mem = resource.getrusage(resource.RUSAGE_SELF).ru_maxrss / rusage_denom
return mem
rusage_denom *= rusage_denom
return resource.getrusage(resource.RUSAGE_SELF).ru_maxrss / rusage_denom
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function memory_usage_resource refactored with the following changes:

@@ -1,4 +1,5 @@
''' Super simple module to create basic random data for tutorials'''

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lines 14-14 refactored with the following changes:

Comment on lines -9 to +34
csv_file = open('cms_scrape.csv', 'w')
with open('cms_scrape.csv', 'w') as csv_file:
csv_writer = csv.writer(csv_file)
csv_writer.writerow(['headline', 'summary', 'video_link'])

csv_writer = csv.writer(csv_file)
csv_writer.writerow(['headline', 'summary', 'video_link'])
for article in soup.find_all('article'):
headline = article.h2.a.text
print(headline)

for article in soup.find_all('article'):
headline = article.h2.a.text
print(headline)
summary = article.find('div', class_='entry-content').p.text
print(summary)

summary = article.find('div', class_='entry-content').p.text
print(summary)
try:
vid_src = article.find('iframe', class_='youtube-player')['src']

try:
vid_src = article.find('iframe', class_='youtube-player')['src']
vid_id = vid_src.split('/')[4]
vid_id = vid_id.split('?')[0]

vid_id = vid_src.split('/')[4]
vid_id = vid_id.split('?')[0]
yt_link = f'https://youtube.com/watch?v={vid_id}'
except Exception as e:
yt_link = None

yt_link = f'https://youtube.com/watch?v={vid_id}'
except Exception as e:
yt_link = None
print(yt_link)

print(yt_link)
print()

print()

csv_writer.writerow([headline, summary, yt_link])

csv_file.close()
csv_writer.writerow([headline, summary, yt_link])
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lines 9-37 refactored with the following changes:

Comment on lines -13 to +17
messages.success(request, f'Your account has been created! You are now able to log in')
messages.success(
request,
'Your account has been created! You are now able to log in',
)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function register refactored with the following changes:

Comment on lines -30 to +34
messages.success(request, f'Your account has been updated!')
messages.success(request, 'Your account has been updated!')
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function profile refactored with the following changes:

if self.request.user == post.author:
return True
return False
return self.request.user == post.author
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function PostUpdateView.test_func refactored with the following changes:

Comment on lines -74 to +72
if self.request.user == post.author:
return True
return False
return self.request.user == post.author
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function PostDeleteView.test_func refactored with the following changes:

Comment on lines -13 to +17
messages.success(request, f'Your account has been created! You are now able to log in')
messages.success(
request,
'Your account has been created! You are now able to log in',
)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function register refactored with the following changes:

Comment on lines -30 to +34
messages.success(request, f'Your account has been updated!')
messages.success(request, 'Your account has been updated!')
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function profile refactored with the following changes:

if self.request.user == post.author:
return True
return False
return self.request.user == post.author
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function PostUpdateView.test_func refactored with the following changes:

Comment on lines -74 to +72
if self.request.user == post.author:
return True
return False
return self.request.user == post.author
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function PostDeleteView.test_func refactored with the following changes:

Comment on lines -13 to +17
messages.success(request, f'Your account has been created! You are now able to log in')
messages.success(
request,
'Your account has been created! You are now able to log in',
)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function register refactored with the following changes:

Comment on lines -30 to +34
messages.success(request, f'Your account has been updated!')
messages.success(request, 'Your account has been updated!')
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function profile refactored with the following changes:

if self.request.user == post.author:
return True
return False
return self.request.user == post.author
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function PostUpdateView.test_func refactored with the following changes:

mem = resource.getrusage(resource.RUSAGE_SELF).ru_maxrss / rusage_denom
return mem
rusage_denom *= rusage_denom
return resource.getrusage(resource.RUSAGE_SELF).ru_maxrss / rusage_denom
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function memory_usage_resource refactored with the following changes:

if day.weekday() == 5 or day.weekday() == 6:
return False
return True
return day.weekday() not in [5, 6]
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Employee.is_workday refactored with the following changes:

self.employees = []
else:
self.employees = employees
self.employees = [] if employees is None else employees
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Manager.__init__ refactored with the following changes:

def sentence(sentence):
for word in sentence.split():
yield word
yield from sentence.split()
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function sentence refactored with the following changes:

  • Replace yield inside for loop with yield from (yield-from)

Comment on lines -32 to +33
total_1 = total_1 + random.randint(-6, 8)
total_2 = total_2 + random.randint(-5, 6)
total_1 += random.randint(-6, 8)
total_2 += random.randint(-5, 6)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lines 32-33 refactored with the following changes:

  • Replace assignment with augmented assignment (aug-assign)

for item in pl_response['items']:
vid_ids.append(item['contentDetails']['videoId'])

vid_ids = [item['contentDetails']['videoId'] for item in pl_response['items']]
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lines 28-31 refactored with the following changes:

for item in pl_response['items']:
vid_ids.append(item['contentDetails']['videoId'])

vid_ids = [item['contentDetails']['videoId'] for item in pl_response['items']]
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lines 23-26 refactored with the following changes:

if balance < 0:
balance = 0

balance = max(balance, 0)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lines 21-23 refactored with the following changes:

# print(json.dumps(data, indent=2))

usd_rates = dict()
usd_rates = {}
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lines 11-11 refactored with the following changes:

@@ -1,4 +1,5 @@
''' Super simple module to create basic random data for tutorials'''

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lines 14-14 refactored with the following changes:

def __init__(self, first, last, pay, employees=None):
super().__init__(first, last, pay)
self.employees = employees if employees else []
self.employees = employees or []
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Manager.__init__ refactored with the following changes:

@sourcery-ai
Copy link
Author

sourcery-ai bot commented Jan 3, 2022

Sourcery Code Quality Report

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

Quality metrics Before After Change
Complexity 2.73 ⭐ 2.48 ⭐ -0.25 👍
Method Length 33.72 ⭐ 32.84 ⭐ -0.88 👍
Working memory 6.98 🙂 6.90 🙂 -0.08 👍
Quality 79.01% 79.39% 0.38% 👍
Other metrics Before After Change
Lines 1065 1058 -7
Changed files Quality Before Quality After Quality Change
mem_profile_old.py 90.23% ⭐ 93.57% ⭐ 3.34% 👍
random_data.py 51.32% 🙂 51.32% 🙂 0.00%
BeautifulSoup/scrape.py 64.47% 🙂 67.04% 🙂 2.57% 👍
Django_Blog/07-Login-Logout-Authentication/django_project/users/views.py 82.18% ⭐ 82.31% ⭐ 0.13% 👍
Django_Blog/08-Profile-And-Images/django_project/users/views.py 82.18% ⭐ 82.31% ⭐ 0.13% 👍
Django_Blog/09-Update-User-Profile/django_project/users/views.py 72.59% 🙂 72.74% 🙂 0.15% 👍
Django_Blog/10-Posts-Create-Update-Delete/django_project/blog/views.py 95.11% ⭐ 96.70% ⭐ 1.59% 👍
Django_Blog/10-Posts-Create-Update-Delete/django_project/users/views.py 72.59% 🙂 72.74% 🙂 0.15% 👍
Django_Blog/11-Pagination/django_project/blog/views.py 95.36% ⭐ 96.75% ⭐ 1.39% 👍
Django_Blog/11-Pagination/django_project/users/views.py 72.59% 🙂 72.74% 🙂 0.15% 👍
Django_Blog/12-Password-Reset/django_project/blog/views.py 95.36% ⭐ 96.75% ⭐ 1.39% 👍
Django_Blog/12-Password-Reset/django_project/users/views.py 72.59% 🙂 72.74% 🙂 0.15% 👍
Django_Blog/13-AWS-S3-Uploads/django_project/blog/views.py 95.36% ⭐ 96.75% ⭐ 1.39% 👍
Django_Blog/13-AWS-S3-Uploads/django_project/users/views.py 72.59% 🙂 72.74% 🙂 0.15% 👍
Django_Blog/13-Deployment-Heroku/django_project/blog/views.py 95.36% ⭐ 96.75% ⭐ 1.39% 👍
Django_Blog/13-Deployment-Heroku/django_project/users/views.py 72.59% 🙂 72.74% 🙂 0.15% 👍
Django_Blog/13-Deployment-Linode/django_project/blog/views.py 95.36% ⭐ 96.75% ⭐ 1.39% 👍
Django_Blog/13-Deployment-Linode/django_project/users/views.py 72.59% 🙂 72.74% 🙂 0.15% 👍
Ex-Machina/ex-machina.py 85.37% ⭐ 85.63% ⭐ 0.26% 👍
Generators/mem_profile.py 90.23% ⭐ 93.57% ⭐ 3.34% 👍
Object-Oriented/3-Class-Static-Methods/oop.py 87.81% ⭐ 88.17% ⭐ 0.36% 👍
Object-Oriented/4-Inheritance/oop-finish.py 91.66% ⭐ 92.27% ⭐ 0.61% 👍
Python/Iterators-Coding-Problem/iter-demo.py 96.41% ⭐ 96.43% ⭐ 0.02% 👍
Python/Matplotlib/09-LiveData/data_gen.py 65.56% 🙂 66.11% 🙂 0.55% 👍
Python/YouTube-API/02-Playlist-Duration/playlist.py 31.70% 😞 33.60% 😞 1.90% 👍
Python/YouTube-API/03-Most-Popular-Video-Playlist/start.py 48.94% 😞 51.26% 🙂 2.32% 👍
Python-Future-Date/credit.py 63.04% 🙂 65.16% 🙂 2.12% 👍
Python-JSON/api.py 82.05% ⭐ 82.21% ⭐ 0.16% 👍
Python-Random/random_data.py 51.32% 🙂 51.32% 🙂 0.00%
Starting_Code/employee.py 95.27% ⭐ 95.29% ⭐ 0.02% 👍

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

File Function Complexity Length Working Memory Quality Recommendation

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants