#!/usr/bin/python -tt # coding: utf-8 # # Copyright (C) 2008 Red Hat Inc. # Author: Luke Macken # # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; either version 2 of the License, or (at your # option) any later version. See http://www.gnu.org/copyleft/gpl.html for # the full text of the license. """ Fedora Weekly Wiki Metrics """ import simplejson from urllib import urlencode from urllib2 import urlopen from datetime import datetime, timedelta now = datetime.utcnow() then = now - timedelta(days=7) query = urlencode({ 'list' : 'recentchanges', 'format' : 'json', 'action' : 'query', 'rcprop' : 'user|title', 'rcend' : then.isoformat().split('.')[0] + 'Z', 'rclimit' : 500, }) data = simplejson.load(urlopen('http://fedoraproject.org/w/api.php', query)) print "From %s to %s" % (then, now) num_changes = len(data['query']['recentchanges']) print "%d wiki changes in the past week" % num_changes if num_changes == 500: print "Warning: Number of changes exceeds the API return limit." print "These results will not be accurate unless run from bot account." users = {} # {username: [change,]} pages = {} # {pagename: # of edits} for change in data['query']['recentchanges']: if not change['user'] in users: users[change['user']] = [] users[change['user']].append(change['title']) if not change['title'] in pages: pages[change['title']] = 0 pages[change['title']] += 1 print '\n== Most active wiki users ==' for user, changes in sorted(users.items(), cmp=lambda x, y: cmp(len(x[1]), len(y[1])), reverse=True)[:10]: print ' %-50s %d' % (('[[:User:%s]]' % user).ljust(50, '.'), len(changes)) print '\n== Most edited pages ==' for page, num in sorted(pages.items(), cmp=lambda x, y: cmp(x[1], y[1]), reverse=True)[:10]: print ' %-50s %d' % (('[[%s]]' % page).ljust(50, '.'), num)