Revscoring rev_doc injection demo

In this notebook, we'll demonstrate injecting a revision document a scoring.

import mwapi

session = mwapi.Session("https://en.wikipedia.org")
doc = session.get(action="query", prop="revisions", revids=[758676335], formatversion=2, rvprop=["ids", "user", "timestamp", "userid", "comment", "size", "contentmodel", "content"])
Sending requests with default User-Agent.  Set 'user_agent' on mwapi.Session to quiet this message.
rev_doc = doc['query']['pages'][0]['revisions'][0]
rev_doc['page'] = {k: v for k, v in doc['query']['pages'][0].items() if k != 'revisions'}
rev_doc
{'comment': '',
 'content': '<gallery caption="123">\nFile:Project 1164 Moskva 2009 G1.jpg|test\n</gallery>',
 'contentformat': 'text/x-wiki',
 'contentmodel': 'wikitext',
 'page': {'ns': 2, 'pageid': 45657000, 'title': 'User:Arlolra/sandbox'},
 'parentid': 758179841,
 'revid': 758676335,
 'size': 76,
 'timestamp': '2017-01-06T21:53:35Z',
 'user': 'Arlolra',
 'userid': 6127236}
pre_save_rev_doc = dict(rev_doc)
pre_save_rev_doc['*'] = "I have a fucking shitty lively ass bunch of coconuts"
del pre_save_rev_doc['content']
pre_save_rev_doc['parentid'] = 642345234
pre_save_rev_doc['revid'] = 0
pre_save_rev_doc['size'] = len(bytes("I have a fucking shitty lively ass bunch of coconuts", 'utf-8'))
pre_save_rev_doc['timestamp'] = '2017-01-11T21:53:35Z'
pre_save_rev_doc['user'] = "127.0.0.1"
pre_save_rev_doc['userid'] = 0
pre_save_rev_doc['page']['ns'] = 0

pre_save_rev_doc
{'*': 'I have a fucking shitty lively ass bunch of coconuts',
 'comment': '',
 'contentformat': 'text/x-wiki',
 'contentmodel': 'wikitext',
 'page': {'ns': 0, 'pageid': 45657000, 'title': 'User:Arlolra/sandbox'},
 'parentid': 642345234,
 'revid': 0,
 'size': 52,
 'timestamp': '2017-01-11T21:53:35Z',
 'user': '127.0.0.1',
 'userid': 0}
import requests
import json

response = requests.get(
    "https://ores-staging.wmflabs.org/v2/scores/enwiki/damaging/0", 
    params={'datasource.revision.doc': json.dumps(pre_save_rev_doc),})

response.json()
{'scores': {'enwiki': {'damaging': {'scores': {'0': {'prediction': True,
      'probability': {'false': 0.36508932740844835,
       'true': 0.6349106725915517}}},
    'version': '0.3.0'}}}}