Skip to content
Find file
Fetching contributors…
Cannot retrieve contributors at this time
executable file 67 lines (53 sloc) 1.95 KB
#!/usr/bin/env python
In this module you'll find a function wikipedia_updates which takes a callback
function which will be passed wikipedia updates that stream from the
server at
Each update will be passed to your callback function will be a Python dictionary
that looks something like:
'anonymous': False,
'comment': '/* Anatomy */ changed statement that orbit was the eye to saying
that the orbit was the eye socket for accuracy',
'delta': 7,
'flag': '',
'namespace': 'article',
'newPage': False,
'page': 'Optic nerve',
'pageUrl': '',
'robot': False,
'unpatrolled': False,
'url': '',
'user': 'Moearly',
'userUrl': '',
'wikipedia': '#en.wikipedia',
'wikipediaLong': 'English Wikipedia',
'wikipediaShort': 'en',
'wikipediaUrl': ''
You'll need the requests ( library installed
for the HTTP requests.
More about the protocol that uses can be found at:
import re
import json
import time
from requests import post, get
def wikipedia_updates(callback):
endpoint = ""
endpoint = "http://localhost:3000/"
session_id = post(endpoint).content.split(':')[0]
xhr_endpoint = "/".join((endpoint, "xhr-polling", session_id))
while True:
t = time.time() * 1000000
response = get(xhr_endpoint, params={'t': t}).content.decode('utf-8')
chunks = re.split(u'\ufffd[0-9]+\ufffd', response)
for chunk in chunks:
parts = chunk.split(':', 3)
if len(parts) == 4:
if __name__ == "__main__":
def print_page(update):
print update
Jump to Line
Something went wrong with that request. Please try again.