Revision: 4404 Author: leogregianin Date: 2007-10-03 14:55:17 +0000 (Wed, 03 Oct 2007)
Log Message: ----------- Patch 1784625 by Leszek Krupi?\197?\132ski
Modified Paths: -------------- trunk/pywikipedia/pagegenerators.py
Modified: trunk/pywikipedia/pagegenerators.py =================================================================== --- trunk/pywikipedia/pagegenerators.py 2007-10-03 14:30:15 UTC (rev 4403) +++ trunk/pywikipedia/pagegenerators.py 2007-10-03 14:55:17 UTC (rev 4404) @@ -505,6 +505,17 @@ seenPages.append(page) yield page
+def RegexFilterPageGenerator(generator, regex): + """ + Wraps around another generator. Yields only thos pages, which titles are positively + matched to regex. + """ + reg = re.compile(regex, re.I) + + for page in generator: + if reg.match(page.titleWithoutNamespace()): + yield page + def CombinedPageGenerator(generators): """ Wraps around a list of other generators. Yields all pages generated by the @@ -735,11 +746,17 @@ else: gen = NewpagesPageGenerator(number = 60) elif arg.startswith('-google'): - if len(arg) == 8: + if len(arg) == 7: googleQuery = wikipedia.input(u'What do you want to search for?') else: googleQuery = arg[8:] gen = GoogleSearchPageGenerator(googleQuery) + elif arg.startswith('-regex'): + if len(arg) == 6: + regex = wikipedia.input(u'What page names are you looking for?') + else: + regex = arg[7:] + gen = RegexFilterPageGenerator(wikipedia.getSite().allpages(), regex) elif arg.startswith('-yahoo'): if len(arg) == 7: query = wikipedia.input(u'What do you want to search for?')