http://www.mediawiki.org/wiki/Special:Code/pywikipedia/9549
Revision: 9549
Author: valhallasw
Date: 2011-09-25 13:49:17 +0000 (Sun, 25 Sep 2011)
Log Message:
-----------
Added 'replacementfile' option, allowing replacements to be read in from a file.
Every line of the file is interpreted as if it was an extra replacement
parameter on the command line.
I.e.: file containing lines 'x' and 'y', and calling
replace.py a -replacementfile:file d
will replace 'a' with 'x' and 'y' with 'd'. This should
also work with regexps, although I'm not 100% sure how they will be interpreted by
open().
Modified Paths:
--------------
trunk/pywikipedia/replace.py
Modified: trunk/pywikipedia/replace.py
===================================================================
--- trunk/pywikipedia/replace.py 2011-09-25 13:33:27 UTC (rev 9548)
+++ trunk/pywikipedia/replace.py 2011-09-25 13:49:17 UTC (rev 9549)
@@ -101,6 +101,14 @@
It is possible to introduce more than one pair of old text
and replacement.
+-replacementfile Lines from the given file name(s) will be read as if they
+ were added to the command line at that point. I.e. a file
+ containing lines "a" and "b", used as
+ python replace.py -page:X -replacementfile:file c d
+ will replace 'a' with 'b' and 'c' with
'd'. However, using
+ python replace.py -page:X c -replacementfile:file d will
+ also work, and will replace 'c' with 'a' and
'b' with 'd'.
+
Examples:
If you want to change templates from the old syntax, e.g. {{msg:Stub}}, to the
@@ -607,6 +615,13 @@
u'Please enter the filename to save the titles:')
else:
filename = arg[6:]
+ elif arg.startswith('-replacementfile'):
+ if len(arg) == len('-replacementfile'):
+ replacefile = pywikibot.input(
+u"""Please enter the filename to read replacements
from:""")
+ else:
+ replacefile = arg[len('-replacementfile')+1:]
+ commandline_replacements.extend([x[:-1] for x in open(replacefile)])
elif arg.startswith('-excepttitle:'):
exceptions['title'].append(arg[13:])
elif arg.startswith('-requiretitle:'):