diff --git a/App/templates/App/task4.html b/App/templates/App/task4.html new file mode 100644 index 0000000..6703e1f --- /dev/null +++ b/App/templates/App/task4.html @@ -0,0 +1,112 @@ +{% load static %} + + + + + Microtask 4 + + + + + +
+ +
+

Tool to analyse quality of last 5 edits made by user

+
+
+ {% csrf_token %} +
+
+ + +
+
+
+
+ +
+
+
+
+ + {% if error %} +
+
+
+
+ {{error}} +
+
+
+
+ {% endif %} + +
+
+
+
+ About analysis parameters +

+

    +
  • Edit Quality +
  • Goodfaith: predicts whether an edit was saved in good-faith
  • +
  • Damaging: predicts whether or not an edit causes damage
  • +
  • Reverted: predicts whether an edit will eventually be reverted
  • +
    +
  • Article Quality +
  • Draft Qulity: predicts if the article will need to be speedy deleted (spam, vandalism, attack, or OK)
  • +
  • Assessment scale: predicts the (Wikipedia 1.0-like) assessment class of an article or draft
  • + +
+

+
+
+
+
+ + + {% for x in articles %} + +
+
+
+
+ User : {{x.user}} +
    +
  • Title = {{x.title}}
  • +
  • Comment = {{x.comment}}
  • +
  • Timestamp = {{x.timestamp}}
  • +
  • revisionID = {{x.revid}}
  • +
  • + Click here to check the difference.

    +
  • +
  • Edit Quality +
  • Goodfaith = {{x.goodfaith}}
  • +
  • Damaging = {{x.damaging}}
  • +
  • Reverted = {{x.reverted}}
  • +
    +
  • Article Quality +
  • Draft Quality = {{x.draftquality}}
  • +
  • Assessment Rating = {{x.quality}}
  • + +
+
+
+
+
+ + {% endfor %} + + + diff --git a/App/views.py b/App/views.py new file mode 100644 index 0000000..ae61054 --- /dev/null +++ b/App/views.py @@ -0,0 +1,70 @@ +import json +import requests +import urllib.parse + +from django.http import HttpResponse +from django.shortcuts import render + + +def user_revisions_analysis(request): + """ + Display analysis of last 5 edits made by 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/task4.html", {"error": "Please enter a username"}) + # if username is not blank + details = list() + parameters = {'action':'query', + 'format':'json', + 'list':'usercontribs', + 'uclimit':'5', + 'ucuser':username} + url_base = 'https://en.wikipedia.org/w/api.php?' + # Recieved data in json-format + response = requests.get(url_base, params = parameters) + if response.status_code == 200: + try: + # Edit data extracted + edits_data = json.loads(response.text) + if 'error' in edits_data: + raise Error(edits_data['error']['info']) + contributions = [i for i in edits_data['query']['usercontribs']] + # if user has no edits + if len(contributions) == 0: + raise Error("0 edits found for username {}".format(username)) + for articles in contributions: + url_ores = "https://ores.wikimedia.org/v3/scores/enwiki/{}".format(str(articles['revid'])) + # recieve ORES response + response2 = requests.get(url_ores) + if response2.status_code != 200: + raise Error("ORES failed to return response") + # if successfull response from ORES + data = json.loads(response2.text) + analysis = data['enwiki']['scores'][str(articles['revid'])] + predictions = {'goodfaith': analysis['goodfaith']['score']['prediction'], + 'reverted': analysis['reverted']['score']['prediction'], + 'damaging': analysis['damaging']['score']['prediction'], + 'draftquality': analysis['draftquality']['score']['prediction'], + 'quality': analysis['wp10']['score']['prediction'], + 'title': articles['title'], + 'comment': articles['comment'], + 'timestamp': articles['timestamp'], + 'revid': articles['revid'], + 'user': articles['user']} + details.append(predictions) + except Exception as err: + return(render(request, + 'App/task4.html', + {'error': err})) + context = {'articles': details} + return render(request, 'App/task4.html', context) + else: + return render(request, + 'App/index.html', + {"error": 'Exit code {}'.format(str(response.status_code))}) + else: + return render(request,'App/task4.html',{})