-
Notifications
You must be signed in to change notification settings - Fork 0
Microtask 1 #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?
Microtask 1 #1
Changes from 4 commits
d7b2d0e
5ad9407
cc7ea89
8133e9a
6dd4900
ef6bda9
8c861d6
7bbf540
db47853
97357e5
3553348
863165f
2f5e74d
efcde18
a613a35
f5c41a7
8969f0c
fee5636
c9e8057
7659411
66399e5
1581136
8df73a2
a8c655b
4c4a59f
a7fea46
f3d082f
75a14b6
0edfcac
cb49836
6e7a318
7f5fbe8
81cd71a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| <!DOCTYPE html> | ||
| <html> | ||
| <head> | ||
| <title> USER CONTRIBUTION SUMMARY </title> | ||
| </head> | ||
| <body> | ||
| <center> | ||
| <form method="post"> | ||
| {% csrf_token %} | ||
| Enter Username: <input type="text" name="username"> | ||
| <br> | ||
| <br> | ||
| <button type='submit'> Submit </button> | ||
| </form> | ||
| </center> | ||
|
|
||
| <h2> | ||
| {% if userid %} | ||
| Username = {{username}} <br> | ||
| Userid = {{userid}} <br> | ||
| <a href="https://phabricator.wikimedia.org/p/{{username}}/"> Profile link </a> | ||
| <br> | ||
| <br> | ||
| <h1>English Edits- </h1><br> | ||
| {% endif %} | ||
| </h2> | ||
| {% for x in contribution %} <!-- Here I traverse all the contributions and display the following div--> | ||
| <div> | ||
| Title = {{x.title}} <br> | ||
| PageID = {{x.pageid}} <br> | ||
| RevisionID = {{x.revid}} <br> | ||
| ParentID = {{x.parentid}} <br> | ||
| ns = {{x.ns}} <br> | ||
| Timestamp = {{x.timestamp}} <br> | ||
| Comment = {{x.comment}} <br> | ||
| Size = {{x.size}} <br> | ||
|
|
||
| <a href="https://en.wikipedia.org/w/index.php?title=User:{{x.user}}&diff=prev&oldid={{x.revid}}"> | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Technically, that's not valid HTML (which is why Github shows it in red); special characters like
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Rectified . |
||
| click here to revise edit. | ||
| </a> | ||
|
|
||
| <br><br><br> | ||
|
|
||
| <div> | ||
| {% endfor %} | ||
| </body> | ||
| </html> | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| from django.http import HttpResponse | ||
| from django.shortcuts import render | ||
| import json | ||
| import requests | ||
|
|
||
| def index(request): | ||
| return HttpResponse("Hello, world. You're at the polls index.") | ||
|
|
||
| def main(request): | ||
| if(request.method=='POST'): | ||
| usr = request.POST['username'] #Here, we get the useranme fetched from html page | ||
| URL = "https://en.wikipedia.org/w/api.php?action=query&format=json&list=usercontribs&ucuser=" | ||
| URL = URL + usr | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What it the username contains a
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Handled the situation. 👍 |
||
| r = requests.get(URL) #Recieved data in json-format | ||
| lst = json.loads(r.text) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The request might fail (e.g. the API is down and responds with HTTP 503), in which case this won't work.
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok. Will handle this, when response code is other than 200.
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
| sub_lst = lst['query']['usercontribs'] #Contribution data extracted | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The API might respond with an error, in which case this key might not exist. (You can test with a username containing
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Resolved. |
||
| try: | ||
| fetched_user = sub_lst[0]['user'] | ||
| fetched_user_id = sub_lst[0]['userid'] | ||
| except: | ||
| fetched_user = fetched_user_id = 'No user found' | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Or possibly the user was found but has no edits.
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. okay , this was a loophole, will handle it 👍 |
||
| return(render(request,'App/index.html',{'contribution':sub_lst, 'username':fetched_user, 'userid':fetched_user_id})) #Here I send contribution for display on index.html page | ||
| else: | ||
| return(render(request,'App/index.html',{})) | ||
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.
The Phabricator username is not typically the same as the wiki username.
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.
Alright. I added that link to augment to the information. Since I just got to know that phabricator and wiki usernames are not same, I'd rather remove this link. Thank you .