@@ -0,0 +1,2920 @@
+#!/usr/bin/python -tt%0A# coding: utf-8%0A#%0A# Copyright (C) 2008 Red Hat Inc.%0A# Authors: Luke Macken %3Clmacken@redhat.com%3E%0A#%0A# This program is free software; you can redistribute it and/or modify it%0A# under the terms of the GNU General Public License as published by the%0A# Free Software Foundation; either version 2 of the License, or (at your%0A# option) any later version.  See http://www.gnu.org/copyleft/gpl.html for%0A# the full text of the license.%0A%0A%22%22%22%0AFedora Wiki Client%0A%22%22%22%0A%0Afrom datetime import datetime, timedelta%0Afrom collections import defaultdict%0A%0Afrom fedora.client import BaseClient%0A%0Aclass FedoraWiki(BaseClient):%0A%0A    def __init__(self, *args, **kw):%0A        super(FedoraWiki, self).__init__('http://fedoraproject.org/w/',%0A                                         *args, **kw)%0A%0A    def get_recent_changes(self, now, then, limit=500):%0A        %22%22%22 Get recent wiki changes from %60now%60 until %60then%60 %22%22%22%0A        data = self.send_request('api.php', req_params=%7B%0A                'list'    : 'recentchanges',%0A                'action'  : 'query',%0A                'format'  : 'json',%0A                'rcprop'  : 'user%7Ctitle',%0A                'rcend'   : then.isoformat().split('.')%5B0%5D + 'Z',%0A                'rclimit' : limit,%0A                %7D)%0A        if 'error' in data:%0A            raise Exception(data%5B'error'%5D%5B'info'%5D)%0A        return data%0A%0A    def print_recent_changes(self, days=7, show=10):%0A        now = datetime.utcnow()%0A        then = now - timedelta(days=days)%0A        print %22From %25s to %25s%22 %25 (then, now)%0A        data = self.get_recent_changes(now=now, then=then)%0A        num_changes = len(data%5B'query'%5D%5B'recentchanges'%5D)%0A        print %22%25d wiki changes in the past week%22 %25 num_changes%0A        if num_changes == 500:%0A            print %22Warning: Number of changes reaches the API return limit.%22%0A            print %22You will not get the complete list of changes unless %22%0A            print %22you run this script using a 'bot' account.%22%0A%0A        users = defaultdict(list) # %7Busername: %5Bchange,%5D%7D%0A        pages = defaultdict(int)  # %7Bpagename: # of edits%7D%0A%0A        for change in data%5B'query'%5D%5B'recentchanges'%5D:%0A            users%5Bchange%5B'user'%5D%5D.append(change%5B'title'%5D)%0A            pages%5Bchange%5B'title'%5D%5D += 1%0A%0A        print '%5Cn== Most active wiki users =='%0A        for user, changes in sorted(users.items(),%0A                                    cmp=lambda x, y: cmp(len(x%5B1%5D), len(y%5B1%5D)),%0A                                    reverse=True)%5B:show%5D:%0A            print ' %25-50s %25d' %25 (('%25s' %25 user).ljust(50, '.'),%0A                                  len(changes))%0A%0A        print '%5Cn== Most edited pages =='%0A        for page, num in sorted(pages.items(),%0A                                cmp=lambda x, y: cmp(x%5B1%5D, y%5B1%5D),%0A                                reverse=True)%5B:show%5D:%0A            print ' %25-50s %25d' %25 (('%25s' %25 page).ljust(50, '.'), num)%0A%0Aif __name__ == '__main__':%0A    wiki = FedoraWiki()%0A    wiki.print_recent_changes()%0A

Add an initial fedora.client.wiki module.