Skip to content

Conversation

@sourcery-ai
Copy link

@sourcery-ai sourcery-ai bot commented Jun 23, 2023

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 AyomideA-S June 23, 2023 11:23
Comment on lines +3 to +16

import requests
import sys

if __name__ == "__main__":
url = "https://jsonplaceholder.typicode.com/"
user = requests.get(url + "users/{}".format(sys.argv[1])).json()
todos = requests.get(url + "todos", params={"userId": sys.argv[1]}).json()
user = requests.get(f"{url}users/{sys.argv[1]}").json()
todos = requests.get(f"{url}todos", params={"userId": sys.argv[1]}).json()

completed = [t.get("title") for t in todos if t.get("completed") is True]
print("Employee {} is done with tasks({}/{}):".format(
user.get("name"), len(completed), len(todos)))
[print("\t {}".format(c)) for c in completed]
print(
f'Employee {user.get("name")} is done with tasks({len(completed)}/{len(todos)}):'
)
[print(f"\t {c}") for c in completed]
Copy link
Author

Choose a reason for hiding this comment

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

Lines 8-14 refactored with the following changes:

@@ -1,17 +1,18 @@
#!/usr/bin/python3
"""Exports to-do list information for a given employee ID to CSV format."""

Copy link
Author

Choose a reason for hiding this comment

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

Lines 10-14 refactored with the following changes:

@@ -1,17 +1,18 @@
#!/usr/bin/python3
"""Exports to-do list information for a given employee ID to JSON format."""

Copy link
Author

Choose a reason for hiding this comment

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

Lines 10-14 refactored with the following changes:

Comment on lines +3 to +27

import json
import requests

if __name__ == "__main__":
url = "https://jsonplaceholder.typicode.com/"
users = requests.get(url + "users").json()
users = requests.get(f"{url}users").json()

with open("todo_all_employees.json", "w") as jsonfile:
json.dump({
u.get("id"): [{
"task": t.get("title"),
"completed": t.get("completed"),
"username": u.get("username")
} for t in requests.get(url + "todos",
params={"userId": u.get("id")}).json()]
for u in users}, jsonfile)
json.dump(
{
u.get("id"): [
{
"task": t.get("title"),
"completed": t.get("completed"),
"username": u.get("username"),
}
for t in requests.get(
f"{url}todos", params={"userId": u.get("id")}
).json()
]
for u in users
},
jsonfile,
)
Copy link
Author

Choose a reason for hiding this comment

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

Lines 8-18 refactored with the following changes:

def number_of_subscribers(subreddit):
"""Return the total number of subscribers on a given subreddit."""
url = "https://www.reddit.com/r/{}/about.json".format(subreddit)
url = f"https://www.reddit.com/r/{subreddit}/about.json"
Copy link
Author

Choose a reason for hiding this comment

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

Function number_of_subscribers refactored with the following changes:

def top_ten(subreddit):
"""Print the titles of the 10 hottest posts on a given subreddit."""
url = "https://www.reddit.com/r/{}/hot/.json".format(subreddit)
url = f"https://www.reddit.com/r/{subreddit}/hot/.json"
Copy link
Author

Choose a reason for hiding this comment

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

Function top_ten refactored with the following changes:

count (int): The parameter of results matched thus far.
"""
url = "https://www.reddit.com/r/{}/hot/.json".format(subreddit)
url = f"https://www.reddit.com/r/{subreddit}/hot/.json"
Copy link
Author

Choose a reason for hiding this comment

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

Function count_words refactored with the following changes:

def recurse(subreddit, hot_list=[], after="", count=0):
"""Returns a list of titles of all hot posts on a given subreddit."""
url = "https://www.reddit.com/r/{}/hot/.json".format(subreddit)
url = f"https://www.reddit.com/r/{subreddit}/hot/.json"
Copy link
Author

Choose a reason for hiding this comment

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

Function recurse refactored with the following changes:

Comment on lines +5 to +14

import sys

if __name__ == '__main__':
count_words = __import__('100-count').count_words
if len(sys.argv) < 3:
print("Usage: {} <subreddit> <list of keywords>".format(sys.argv[0]))
print("Ex: {} programming 'python java javascript'".format(
sys.argv[0]))
print(f"Usage: {sys.argv[0]} <subreddit> <list of keywords>")
print(f"Ex: {sys.argv[0]} programming 'python java javascript'")
else:
result = count_words(sys.argv[1], [x for x in sys.argv[2].split()])
result = count_words(sys.argv[1], list(sys.argv[2].split()))
Copy link
Author

Choose a reason for hiding this comment

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

Lines 10-14 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.

1 participant