Skip to content

Instantly share code, notes, and snippets.

#!/usr/bin/env python
# MediaWiki OAuth connector for Flask
#
# Requires flask-oauth
#
# (C) 2013 Merlijn van Deen <valhallasw@arctus.nl>
# Licensed under the MIT License // http://opensource.org/licenses/MIT
#
__version__ = '0.1.14'
@slaporte
slaporte / Recent Changes Feed.md
Created February 3, 2015 17:32
Recent changes feed documentation

Introduction

The recent changes stream is a live, public feed of activity on all Wikimedia wikis, including Wikipedia, available in over 270 languages. Using the recent changes stream, you can build applications on top of the massive amount of realtime data from Wikipedia. This data powers projects that identify trending news topics, sonify and visualize Wikipedia edits, monitor edits from US Congress, and more.

Connecting

An application can connect to the recent changes stream with a SocketIO client. First, connect to stream.wikimedia.org/rc. Then, subscribe to any Wikimedia wiki in the format [language code].[wiki].org.

For example, to connect and subscribe to English Wikipedia:

@slaporte
slaporte / top_editors.py
Created November 12, 2014 09:21
A WSGI app for Tool Labs to fetch the top editors for a wiki
from bottle import route, default_app, debug
from flup.server.fcgi import WSGIServer
from datetime import timedelta, datetime
import os
import oursql
#import jsonp_bottle
def parse_date_string(stamp):
return datetime.strptime(stamp, '%Y%m%d%H%M%S')
@slaporte
slaporte / averages
Last active December 31, 2015 00:09
MariaDB [enwiki_p]> SELECT rc_title, AVG(rc_new_len - rc_old_len) FROM recentchanges WHERE rc_namespace = 0 AND rc_timestamp > 20131203000000 GROUP BY rc_title ORDER BY AVG(rc_new_len - rc_old_len) DESC LIMIT 10;
+---------------------------------------------------------------------------------+------------------------------+
| rc_title | AVG(rc_new_len - rc_old_len) |
+---------------------------------------------------------------------------------+------------------------------+
| Richard_Helms,_early_career | 145301.0000 |
| List_of_Scheduled_prehistoric_Monuments_in_Pembrokeshire_(domestic_and_defence) | 75804.0000 |
| Opinion_polling_for_the_German_federal_election,_2013 | 53762.0000 |
| Taikyoku_shogi | 52598.0000 |
| 1998
"""Markov Chain.
Pass input to stdin.
Usage:
markov <len> [-n <n>] [-p <p>] [-c] [-s <s>]
markov -h | --help
Options:
<len> The length (in tokens) of the output to generate

Barnstar project notes

  • hall of fame for largest edits?
  • tag edit types (revert, simple change, signficant content addition, new page, adding media, adding links, adding categories)

types of edits

  • small / medium / great change
  • {{subst:The Modest Barnstar|message ~~~~|alt}}
(u'DerbethBot', 44014),
(u'Bubel', 17285),
(u'GerardM', 9391),
(u'Jjackoti', 8011),
(u'Booradleyp', 7243),
(u'Smallbot', 6691),
(u'Dvortybot', 5867),
(u'Tsca.bot', 5190),
(u'Dvortygirl', 4745),
(u'Xuezhongwen', 3590),
api = new mw.Api;
api.get({
action: 'query',
prop: 'revisions',
rvlimit: 1,
titles: wgTitle,
rvprop: 'timestamp|user|comment',
meta: 'userinfo'
}).done(function(resp) {
var page_resp = resp['query']['pages'];
We can't make this file beautiful and searchable because it's too large.
page_info['title'],page_info['page_id'],ntd_cite_book,ntd_cite_cl,ntd_cite_count,ntd_cite_episode,ntd_cite_journal,ntd_cite_news,ntd_cite_newsgroup,ntd_cite_patent,ntd_cite_pressrelease,ntd_cite_report,ntd_cite_video,ntd_cite_videogame,ntd_cite_web,ntd_ref_count,ntd_ref_needed_span_count,ntd_ref_text_count,ntd_reflist_count,custom_cite_all,custom_years_list,custom_yearsdetected,custom_tmpl_list,custom_pbl_list,custom_use_count
Mitchell Sanford,34786762,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,[],0,[],[],[]
Karl Hess (painter),26779898,0,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,[],0,[],[],[]
John Lonsdale,19730337,0,3,3,0,0,0,0,0,0,0,0,0,1,9,0,3,1,3,[1893],1,"[u'Cite web', u'Citation', u'None']","[u'None found', [u'Cambridge University Press'], u'None found']","[1, 1, 7]"
Joseph-R̩mi Valli̬res de Saint-R̩al,8901369,0,2,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,[],0,[],[],[]
Felix Auerbach,40066596,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,0,0,0,[],0,[],[],[]
Fran̤ois-Xavier Paradis,19367062,0,1,1,0,0,0,0,0,0,0,0,0,1,2,0,1,1,1,[],0,[u'Cite