summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLuke Macken <lmacken@redhat.com>2008-07-09 13:59:19 -0400
committerLuke Macken <lmacken@redhat.com>2008-07-09 13:59:19 -0400
commitc5b9d613bf8c3eee31e030c6d83da612637c2b70 (patch)
treeb7f5652659e62d83c5880a9c0fc59c28a54970bb
parent402dfff6ce6a42bcb0f541da6c6addb0157b2896 (diff)
downloadfedora-weekly-metrics-c5b9d613bf8c3eee31e030c6d83da612637c2b70.tar.gz
fedora-weekly-metrics-c5b9d613bf8c3eee31e030c6d83da612637c2b70.tar.xz
fedora-weekly-metrics-c5b9d613bf8c3eee31e030c6d83da612637c2b70.zip
Add an initial wiki module that generates metrics for active users, and pagesHEADmaster
-rwxr-xr-xwiki.py62
1 files changed, 62 insertions, 0 deletions
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 <lmacken@redhat.com>
+#
+# 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)