From c5b9d613bf8c3eee31e030c6d83da612637c2b70 Mon Sep 17 00:00:00 2001 From: Luke Macken Date: Wed, 9 Jul 2008 13:59:19 -0400 Subject: Add an initial wiki module that generates metrics for active users, and pages --- wiki.py | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100755 wiki.py diff --git a/wiki.py b/wiki.py new file mode 100755 index 0000000..6fd3695 --- /dev/null +++ b/wiki.py @@ -0,0 +1,62 @@ +#!/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) -- cgit