diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..2f78cf5 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +*.pyc + diff --git a/App/__pycache__/__init__.cpython-34.pyc b/App/__pycache__/__init__.cpython-34.pyc deleted file mode 100644 index 0b58957..0000000 Binary files a/App/__pycache__/__init__.cpython-34.pyc and /dev/null differ diff --git a/App/__pycache__/admin.cpython-34.pyc b/App/__pycache__/admin.cpython-34.pyc deleted file mode 100644 index 6767d87..0000000 Binary files a/App/__pycache__/admin.cpython-34.pyc and /dev/null differ diff --git a/App/__pycache__/models.cpython-34.pyc b/App/__pycache__/models.cpython-34.pyc deleted file mode 100644 index 2d28c14..0000000 Binary files a/App/__pycache__/models.cpython-34.pyc and /dev/null differ diff --git a/App/__pycache__/urls.cpython-34.pyc b/App/__pycache__/urls.cpython-34.pyc deleted file mode 100644 index 4d27c9a..0000000 Binary files a/App/__pycache__/urls.cpython-34.pyc and /dev/null differ diff --git a/App/__pycache__/views.cpython-34.pyc b/App/__pycache__/views.cpython-34.pyc deleted file mode 100644 index 113cc01..0000000 Binary files a/App/__pycache__/views.cpython-34.pyc and /dev/null differ diff --git a/App/migrations/__pycache__/__init__.cpython-34.pyc b/App/migrations/__pycache__/__init__.cpython-34.pyc deleted file mode 100644 index a31bb23..0000000 Binary files a/App/migrations/__pycache__/__init__.cpython-34.pyc and /dev/null differ diff --git a/App/templates/App/home.html b/App/templates/App/home.html new file mode 100644 index 0000000..8fb57d0 --- /dev/null +++ b/App/templates/App/home.html @@ -0,0 +1,43 @@ +{% load static %} + + + + + Outreachy Tasks + + + + + + +
+

Outreachy Microtasks

+
+
+
+
+
+ User Contribution Summary +

A simple tool that takes a username and lists the recent English Wikipedia edits of that user

+
+ +
+
+
+
+
+ User Percentile +

A simple tool that takes a username and tells what percentile the user is at by number of edits.

+
+ +
+
+
+ + diff --git a/App/templates/App/index.html b/App/templates/App/index.html new file mode 100644 index 0000000..36a5183 --- /dev/null +++ b/App/templates/App/index.html @@ -0,0 +1,80 @@ +{% load static %} + + + + + Microtask 1 + + + + + +
+ +
+

Tool to display the recent English Wikipedia edits of that user

+
+
+ {% csrf_token %} +
+
+ + +
+
+
+
+ +
+
+
+
+ {% if error %} +
+
+
+
+ {{error}} +
+
+
+
+ {% endif %} + + {% for x in contribution %} + +
+
+
+
+ User : {{x.user}} +
    +
  • Title = {{x.title}}
  • +
  • PageID = {{x.pageid}}
  • +
  • RevisionID = {{x.revid}}
  • +
  • ParentID = {{x.parentid}}
  • +
  • ns = {{x.ns}}
  • +
  • Timestamp = {{x.timestamp}}
  • +
  • Size = {{x.size}}
  • +
  • + Click here to view the edit. +
  • +
+
+
+
+
+ + {% endfor %} + + + diff --git a/App/urls.py b/App/urls.py index 856d924..235b371 100644 --- a/App/urls.py +++ b/App/urls.py @@ -1,2 +1,11 @@ from django.conf.urls import url +from . import views + +app_name='App' +urlpatterns = [ + url(r'^$', views.index, name='index'), + url(r'^Microtask1/', views.get_recent_english_edits, name='get_recent_english_edits'), + url(r'^Microtask2/', views.get_the_user_percentile, name='get_the_user_percentile'), +] + diff --git a/App/views.py b/App/views.py new file mode 100644 index 0000000..5b259da --- /dev/null +++ b/App/views.py @@ -0,0 +1,66 @@ +import json +import requests +import urllib.parse + +from django.http import HttpResponse +from django.shortcuts import render + + +def get_recent_english_edits(request): + """ + Display the recent english edits of the user. + """ + + if request.method == 'POST': + + # Here, we get the username + username = request.POST['username'] + # if username is submitted blank + if not username: + return render(request, "App/index.html", {"error": "Please enter a username"}) + + # if username is not blank + params = {'action':'query', + 'format':'json', + 'list':'usercontribs', + 'ucuser': username} + + + URL = "https://en.wikipedia.org/w/api.php?" + + # Recieved data in json-format + response = requests.get(URL, params = params) + + if response.status_code == 200: + lst = json.loads(response.text) + try: + # if username contains invalid value + if lst['error']: + return render(request, + 'App/index.html', + {"error":lst['error']['info']} + ) + except: + # Contribution data extracted + sub_lst = lst['query']['usercontribs'] + + # if user has no edits + if len(sub_lst) == 0: + return render(request, + 'App/index.html', + {"error": "0 edits found for username {}".format(username)}) + + # Send contribution data for display + return render(request, + 'App/index.html', + {"contribution": sub_lst, "username": username}) + else: + return render(request, + 'App/index.html', + {"error": 'Exit code {}'.format(str(response.status_code)), + } + ) + + if request.method == 'GET': + return render(request, 'App/index.html') + \ No newline at end of file diff --git a/Project/__pycache__/__init__.cpython-34.pyc b/Project/__pycache__/__init__.cpython-34.pyc deleted file mode 100644 index a4053df..0000000 Binary files a/Project/__pycache__/__init__.cpython-34.pyc and /dev/null differ diff --git a/Project/__pycache__/settings.cpython-34.pyc b/Project/__pycache__/settings.cpython-34.pyc deleted file mode 100644 index 3c93670..0000000 Binary files a/Project/__pycache__/settings.cpython-34.pyc and /dev/null differ diff --git a/Project/__pycache__/urls.cpython-34.pyc b/Project/__pycache__/urls.cpython-34.pyc deleted file mode 100644 index b1e0f2f..0000000 Binary files a/Project/__pycache__/urls.cpython-34.pyc and /dev/null differ diff --git a/Project/settings.py b/Project/settings.py index bed9180..2a0bcac 100644 --- a/Project/settings.py +++ b/Project/settings.py @@ -100,6 +100,10 @@ }, ] +STATICFILES_DIRS = [ + os.path.join(BASE_DIR, "static"), +] + # Internationalization # https://docs.djangoproject.com/en/1.11/topics/i18n/ diff --git a/app.py b/app.py old mode 100644 new mode 100755 index f1b8a9d..47c7e4e --- a/app.py +++ b/app.py @@ -5,4 +5,3 @@ os.environ.setdefault("DJANGO_SETTINGS_MODULE", "Project.settings") app = get_wsgi_application() - diff --git a/static/style.css b/static/style.css new file mode 100644 index 0000000..92a5111 --- /dev/null +++ b/static/style.css @@ -0,0 +1,35 @@ +.center { + text-align: center; +} +.pointer { + cursor: pointer; +} + +.yellow { + color: yellow !important; +} + +nav { + background-color: #64b5f6; + color: white; +} +input:active ~ label, input:valid ~ label { + top:-20px; + font-size:14px; + color:#5264AE; +} + +.blue-color { + background-color: #64b5f6; +} + +.pd-left-20 { + padding-left: 20px; +} +.btn:hover, .btn-large:hover { + background-color: #64b5f6; +} +.btn:focus, .btn-large:focus, .btn-floating:focus { + background-color: #64b5f6; + +} \ No newline at end of file