8000 Sourcery refactored master branch by sourcery-ai[bot] · Pull Request #2 · ekmixon/python-scripts · GitHub
[go: up one dir, main page]

Skip to content

Sourcery refactored master branch #2

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

sourcery-ai[bot]
Copy link
@sourcery-ai sourcery-ai bot commented Aug 17, 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 ekmixon August 17, 2022 15:40
print("Renamed {} to {}".format(file, new_file_name))
print(f"Renamed {file} to {new_file_name}")
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 -3 to +6
my_dict = dict()
my_dict = {}
for key, values in ordered_pairs:
if key in my_dict:
raise ValueError("Duplicate key: {}".format(key,))
raise ValueError(f"Duplicate key: {key}")
Copy link
Author

Choose a reason for hiding this comment

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

Function dict_raise_on_duplicates refactored with the following changes:

Comment on lines -31 to +34
sample_list = list()
sample_list = []
my_list = [random.randint(1, 888898) for num in
range(1, 1000000) if num % 2 == 0]
print('Finished in {} seconds.'.format(timer.duration()))
print(f'Finished in {timer.duration()} seconds.')
Copy link
Author

Choose a reason for hiding this comment

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

Lines 31-34 refactored with the following changes:

Comment on lines -37 to -42
n = 0
all_times = list()
while n < 10:
all_times = []
for _ in range(10):
create_new_db()
load_new_perms()
n += 1
Copy link
Author

Choose a reason for hiding this comment

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

Lines 37-42 refactored with the following changes:

8000
print("\nFound {} links".format(len(links)))
print(f"\nFound {len(links)} links")
Copy link
Author

Choose a reason for hiding this comment

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

Lines 19-19 refactored with the following changes:

print("Config file: {}".format(CONFIGFILE))
print(f"Config file: {CONFIGFILE}")
Copy link
Author

Choose a reason for hiding this comment

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

Lines 42-42 refactored with the following changes:

call(["git", "checkout", str(commit).rstrip()+"~1", file_name])
call(["git", "checkout", f"{str(commit).rstrip()}~1", file_name])
Copy link
Author

Choose a reason for hiding this comment

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

Lines 7-7 refactored with the following changes:

for row in reader:
all_addresses.append(row)
all_addresses.extend(iter(reader))
Copy link
Author

Choose a reason for hiding this comment

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

Function get_addresses refactored with the following changes:

Comment on lines -26 to -36
counter = 1
# update header
header_row = all_the_ip_address.pop(0)
header_row.extend(['Country', 'City'])
# get geolocation
for line in all_the_ip_address:
for counter, line in enumerate(all_the_ip_address, start=1):
print("Grabbing geo info for row # {0}".format(counter))
r = requests.get('https://freegeoip.net/json/{0}'.format(line[0]))
line.extend([str(r.json()['country_name']), str(r.json()['city'])])
updated_addresses.append(line)
counter += 1
Copy link
Author

Choose a reason for hiding this comment

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

Function get_geolocation refactored with the following changes:

Comment on lines -31 to +32
else:
print('Specify at least 1 argument')
sys.exit()
print('Specify at least 1 argument')
sys.exit()
Copy link
Author

Choose a reason for hiding this comment

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

Function get_arguments refactored with the following changes:

@sourcery-ai
Copy link
Author
sourcery-ai bot commented Aug 17, 2022

Sourcery Code Quality Report

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

Quality metrics Before After Change
Complexity 3.59 ⭐ 2.89 ⭐ -0.70 👍
Method Length 38.00 ⭐ 37.64 ⭐ -0.36 👍
Working memory 5.42 ⭐ 5.35 ⭐ -0.07 👍
Quality 81.54% 82.39% 0.85% 👍
Other metrics Before After Change
Lines 592 575 -17
Changed files Quality Before Quality After Quality Change
scripts/04_rename_with_slice.py 77.85% ⭐ 77.70% ⭐ -0.15% 👎
scripts/05_load_json_without_dupes.py 86.59% ⭐ 89.54% ⭐ 2.95% 👍
scripts/06_execution_time.py 89.48% ⭐ 89.56% ⭐ 0.08% 👍
scripts/07_benchmark_permissions_loading_django.py 92.94% ⭐ 93.02% ⭐ 0.08% 👍
scripts/08_basic_email_web_crawler.py 86.02% ⭐ 86.02% ⭐ 0.00%
scripts/09_basic_link_web_crawler.py 88.87% ⭐ 88.87% ⭐ 0.00%
scripts/10_find_files_recursively.py 78.35% ⭐ 80.68% ⭐ 2.33% 👍
scripts/11_optimize_images_with_wand.py 81.19% ⭐ 81.03% ⭐ -0.16% 👎
scripts/12_csv_split.py 76.23% ⭐ 77.74% ⭐ 1.51% 👍
scripts/13_random_name_generator.py 89.63% ⭐ 90.24% ⭐ 0.61% 👍
scripts/15_check_my_environment.py 91.61% ⭐ 92.48% ⭐ 0.87% 👍
scripts/20_restore_file_from_git.py 85.09% ⭐ 84.93% ⭐ -0.16% 👎
scripts/25_ip2geolocation.py 83.17% ⭐ 84.61% ⭐ 1.44% 👍
scripts/30_fullcontact.py 91.58% ⭐ 92.73% ⭐ 1.15% 👍
scripts/31_youtube_sentiment.py 74.17% 🙂 75.25% ⭐ 1.08% 👍
scripts/34_git_all_repos.py 73.07% 🙂 72.93% 🙂 -0.14% 👎

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

File Function Complexity Length Working Memory Quality Recommendation
scripts/11_optimize_images_with_wand.py get_image_file_names 7 ⭐ 78 🙂 10 😞 65.25% 🙂 Extract out complex expressions
scripts/12_csv_split.py parse_file 1 ⭐ 148 😞 8 🙂 66.40% 🙂 Try splitting into smaller methods

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!

Comment on lines -40 to +39
if r.status_code == 200:
return r.text
else:
return "Sorry, no results found."
return r.text if r.status_code == 200 else "Sorry, no results found."
Copy link
Author

Choose a reason for hiding this comment

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

Function call_api refactored with the following changes:

Comment on lines -15 to +16
else:
print('Specify at least 1 argument')
sys.exit()
print('Specify at least 1 argument')
sys.exit()
Copy link
Author

Choose a reason for hiding this comment

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

Function get_arguments refactored with the following changes:

Comment on lines -21 to +23
html = requests.get('https://plus.googleapis.com/u/0/_/widget/render/comments?first_party_property=YOUTUBE&href=' + url)
html = requests.get(
f'https://plus.googleapis.com/u/0/_/widget/render/comments?first_party_property=YOUTUBE&href={url}'
)

Copy link
Author

Choose a reason for hiding this comment

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

Function get_comments refactored with the following changes:

Comment on lines -40 to +46
else:
for word in comment.split(' '):
if word in negative_words:
negative += 1
if word in positive_words:
positive += 1
for word in comment.split(' '):
if word in negative_words:
negative += 1
if word in positive_words:
positive += 1
Copy link
Author

Choose a reason for hiding this comment

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

Function calculate_sentiment refactored with the following changes:

Comment on lines -50 to +51
url = get_arguments()
if url:
if url := get_arguments():
Copy link
Author

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:

Comment on lines +9 to +14
url = 'https://api.github.com/{0}/{1}/repos?per_page=100&page={2}'
while True:
url = 'https://api.github.com/{0}/{1}/repos?per_page=100&page={2}'
r = requests.get(url.format(group, name, page))
if r.status_code == 200:
rdata = r.json()
for repo in rdata:
repo_urls.append(repo['clone_url'])
repo_urls.extend(repo['clone_url'] for repo in rdata)
Copy link
Author

Choose a reason for hiding this comment

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

Function get_total_repos refactored with the following changes:

Comment on lines -28 to -33
count = 1
print('Cloning...')
for repo in all_repos:
os.system('Git clone ' + repo)
for count, repo in enumerate(all_repos, start=1):
os.system(f'Git clone {repo}')
print('Completed repo #{0} of {1}'.format(count, len(all_repos)))
count += 1
Copy link
Author

Choose a reason for hiding this comment

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

Function clone_repos refactored with the following changes:

Comment on lines -37 to +34
total = get_total_repos(sys.argv[1], sys.argv[2])
if total:
if total := get_total_repos(sys.argv[1], sys.argv[2]):
Copy link
Author

Choose a reason for hiding this comment

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

Lines 37-38 refactored with the following changes:

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
0