-
Notifications
You must be signed in to change notification settings - Fork 0
Sourcery refactored master branch #1
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
base: master
Are you sure you want to change the base?
Conversation
|
|
||
| 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] |
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 8-14 refactored with the following changes:
- Use f-string instead of string concatenation [×2] (
use-fstring-for-concatenation) - Replace call to format with f-string [×3] (
use-fstring-for-formatting)
| @@ -1,17 +1,18 @@ | |||
| #!/usr/bin/python3 | |||
| """Exports to-do list information for a given employee ID to CSV format.""" | |||
|
|
|||
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 10-14 refactored with the following changes:
- Use f-string instead of string concatenation [×2] (
use-fstring-for-concatenation) - Replace call to format with f-string [×2] (
use-fstring-for-formatting)
| @@ -1,17 +1,18 @@ | |||
| #!/usr/bin/python3 | |||
| """Exports to-do list information for a given employee ID to JSON format.""" | |||
|
|
|||
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 10-14 refactored with the following changes:
- Use f-string instead of string concatenation [×2] (
use-fstring-for-concatenation) - Replace call to format with f-string [×2] (
use-fstring-for-formatting)
|
|
||
| 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, | ||
| ) |
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 8-18 refactored with the following changes:
- Use f-string instead of string concatenation [×2] (
use-fstring-for-concatenation)
0x16-api_advanced/0-subs.py
Outdated
| 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" |
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 number_of_subscribers refactored with the following changes:
- Replace call to format with f-string (
use-fstring-for-formatting)
0x16-api_advanced/1-top_ten.py
Outdated
| 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" |
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 top_ten refactored with the following changes:
- Replace call to format with f-string (
use-fstring-for-formatting)
| 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" |
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 count_words refactored with the following changes:
- Replace call to format with f-string [×2] (
use-fstring-for-formatting)
0x16-api_advanced/2-recurse.py
Outdated
| 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" |
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 recurse refactored with the following changes:
- Replace call to format with f-string (
use-fstring-for-formatting)
|
|
||
| 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())) |
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 10-14 refactored with the following changes:
- Replace call to format with f-string [×2] (
use-fstring-for-formatting) - Replace identity comprehension with call to collection constructor (
identity-comprehension)
Branch
masterrefactored 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
masterbranch, then run:Help us improve this pull request!