Next question: If I have a set of synonyms in the wiki, and they redirect to the same page (say, cow and cattle), is it possible to find the first time any of these terms occur on a page, and link only that? So cow would be changed to [[cow]], or cattle to [[cattle]], but not both on the same page, if both terms occur.
Many thanks Daniel, this has been a great help - and adding the -exceptinsidetag:header to regex thanks to my request is very good of you.
I have been doing test runs (without saving, as my bot has a problem at the moment) and I am able to successfully use all these terms that you gave. This is wonderful.
Chris
On Mon, Jun 30, 2008 at 3:11 PM, Daniel Herding DHerding@gmx.de wrote:
Am Sonntag 29 Juni 2008 17:51:18 schrieb Chris Watkins:
I am running replace.py and have several questions.
- Can I replace only the first result per page?
That is possible with some regular expression magic:
python replace.py -regex "(?s)foo(.*$)" "bar\1" -page:Fubar
Maybe you have to type \1 instead of \1 if you're using Windows.
- Can I exclude hits within a wikilink, url or header? E.g. can I look
for
appropriate technology but ensure it's not inside a wikilink, e.g. * [[Peter's appropriate technology lamp]] or * [[Wikipedia:Appropriate technology|appropriate technology stuff at Wikipedia]]) or * http://forum.permaculture.org (if I'm looking for "permaculture"). * == Permaculture program ==
You can run this: python replace.py foo bar -page:Fubar -exceptinsidetag:link -exceptinsidetag:hyperlink
This will exclude wikilinks and URLs. There are some more things that can be excluded, see the source code of the method replaceExcept() in wikipedia.py (look at the exceptionRegexes dictionary). I have just added a regular expression for section headers for you, so if you're running the SVN version, you can use this parameter:
-exceptinsidetag:header
Cheers
Daniel
Pywikipedia-l mailing list Pywikipedia-l@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/pywikipedia-l