:)
Trust me, learning how to use python regexp worth it :) (I learned reading this page : http://www.amk.ca/python/howto/regex/ )
In your case, replace.py will do the trick, with something like : "({{cite book[^}]*isbn\s*=\s*)(\d*)" "\1ISBN \2" for the first and both "({{cite book[^}]*)last\s*=\s*(\w*)[^}]*)first\s*=\s*(\w*)" "\1author=\3 \2" "({{cite book[^}]*)first\s*=\s*(\w*)[^}]*)last\s*=\s*(\w*)" "\1author=\2 \3" for the second will work. (but other regexps might also work)
Most of the time, when automated changes are needed, I use replace.py, with a regex. Regular expressions are very, very efficient.
2007/10/9, Lars Aronsson lars@aronsson.se:
Suppose I wanted to change all occurrences of
{{cite book | ... | isbn=123 | ...}} into ... | id=ISBN 123 | ...
or all {{cite book | last=Marx | first=Karl | ...}} into | author=Karl Marx | ...
How would I do that? Apparently template.py can only change the template name (e.g. "cite book" into some other language) and the regexp capability of replace.py quickly makes this a mess, especially when you consider that first=Karl|year=1867|last=Marx is just as valid, and that template calls can contain newlines.
I guess what I want is a robot framework that finds all uses of a specified template (e.g. "cite book") and makes a call to a user-defined function, that receives the template parameters as a dictionary (hash, mapping). Then I could write specific Python code like this:
t[id] = 'ISBN ' + t[isbn] del t[isbn]
t[author] = t[first] + ' ' + t[last] del t[first] del t[last]
This too sounds easy until you consider that parameter values can contain template calls, e.g. {{cite book|...|id={{ISSN|1234-5678}}}}, so simply matching {{.*?}} isn't enough.
And then when the user-defined function returns, the dictionary must be packed back into text, preserving as much as possible of the previous whitespace and newline structure, to minimize the edit diff.
Has anybody tried this?
-- Lars Aronsson (lars@aronsson.se) Aronsson Datateknik - http://aronsson.se
Pywikipedia-l mailing list Pywikipedia-l@lists.wikimedia.org http://lists.wikimedia.org/mailman/listinfo/pywikipedia-l