http://www.mediawiki.org/wiki/Special:Code/pywikipedia/11565
Revision: 11565 Author: xqt Date: 2013-05-20 07:42:02 +0000 (Mon, 20 May 2013) Log Message: ----------- - fix for bug #3613589 - update from trunk: yield page links separated by newlines
Modified Paths: -------------- branches/rewrite/pywikibot/pagegenerators.py
Modified: branches/rewrite/pywikibot/pagegenerators.py =================================================================== --- branches/rewrite/pywikibot/pagegenerators.py 2013-05-19 23:53:02 UTC (rev 11564) +++ branches/rewrite/pywikibot/pagegenerators.py 2013-05-20 07:42:02 UTC (rev 11565) @@ -643,8 +643,9 @@ def TextfilePageGenerator(filename=None, site=None): """Iterate pages from a list in a text file.
- The file must contain page links between double-square-brackets. The - generator will yield each corresponding Page object. + The file must contain page links between double-square-brackets or, in + alternative, separated by newlines. The generator will yield each + corresponding Page object.
@param filename: the name of the file that should be read. If no name is given, the generator prompts the user. @@ -656,13 +657,22 @@ if site is None: site = pywikibot.Site() f = codecs.open(filename, 'r', config.textfile_encoding) + linkmatch = None for linkmatch in pywikibot.link_regex.finditer(f.read()): # If the link is in interwiki format, the Page object may reside # on a different Site than the default. # This makes it possible to work on different wikis using a single # text file, but also could be dangerous because you might # inadvertently change pages on another wiki! - yield pywikibot.Page(pywikibot.Link(linkmatch.groups("title"), site)) + yield pywikibot.Page(pywikibot.Link(linkmatch.group("title"), site)) + if linkmatch is None: + f.seek(0) + for title in f: + title = title.strip() + if '|' in title: + title = title[:title.index('|')] + if title: + yield pywikibot.Page(site, title) f.close()
pywikipedia-svn@lists.wikimedia.org