http://www.mediawiki.org/wiki/Special:Code/pywikipedia/10417
Revision: 10417 Author: multichill Date: 2012-06-23 16:12:26 +0000 (Sat, 23 Jun 2012) Log Message: ----------- Add the EdittimeFilterPageGenerator() generator filter.
Modified Paths: -------------- trunk/pywikipedia/pagegenerators.py
Modified: trunk/pywikipedia/pagegenerators.py =================================================================== --- trunk/pywikipedia/pagegenerators.py 2012-06-23 16:10:55 UTC (rev 10416) +++ trunk/pywikipedia/pagegenerators.py 2012-06-23 16:12:26 UTC (rev 10417) @@ -28,6 +28,7 @@ import re import sys import codecs +import datetime
import urllib, urllib2, time import date, catlib, userlib, query @@ -1131,6 +1132,22 @@ yield page break
+def EdittimeFilterPageGenerator(generator, begintime=datetime.datetime.min, endtime=datetime.datetime.max): + """ + Wraps around another generator. Yields only those pages which were changed + between begintime and endtime. + + @param generator: A generator object + @param begintime: A datetime object. Only pages after this time will be returned. + @param endtime: A datetime object Only pages before this time will be returned. + """ + for page in generator: + if page.editTime(datetime=True)==None: + # FIXME: The page object should probably handle this + page.get() + if page.editTime(datetime=True) and begintime < page.editTime(datetime=True) and page.editTime(datetime=True) < endtime: + yield page + def CombinedPageGenerator(generators): """ Wraps around a list of other generators. Yields all pages generated by