Skip to content

Microtask 5 #5

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

Microtask 5 #5

wants to merge 1 commit into from

Conversation

yashasingh
Copy link
Owner

@yashasingh yashasingh commented Nov 8, 2017

@tgr
Sir,
This tool provides view count of last five edits of user in English wiki in current year.
Tool- link

Please review.
Thank you.

@yashasingh yashasingh changed the title Created task 5 Microtask 5 Nov 8, 2017
username = request.POST['username']
try:
if not username:
raise Error("Please enter a username")
Copy link

Choose a reason for hiding this comment

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

This should be Exception, not Error (I probably remembered wrong). Or you can define your own error type (that has the benefit that you can let other types bubble up to the framework and it will probably show a more developer-friendly error message, with stack traces and whatnot).

url_base = 'https://en.wikipedia.org/w/api.php?'
# Recieved data in json-format
response = requests.get(url_base, params = params)
if response.status_code == 200:
Copy link

Choose a reason for hiding this comment

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

You can use response.raise_for_status() and let exception handling deal with non-200 responses.

# Recieved data in json-format
response = requests.get(url_base, params = params)
if response.status_code == 200:
edits_data = json.loads(response.text)
Copy link

Choose a reason for hiding this comment

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

IIRC you can just call response.json()

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.

2 participants