Forum:Bot search and replace

I'd like to replace all links in a wiki that look like this *PAGENAME at Tolkien Gateway with a template looking like this * The structure is always the same, but PAGENAME differs. Is that possible using AWB or Pywikipediabot? If so... how?

Thanks for your help. -- Weas-El ✉  15:02, November 3, 2011 (UTC)


 * At least for the template call, you should use the magic word . AWB may be able to do it, Pywikipedia could definitely have a script written for it that would allow it to perform that action if it doesn't already have the capability.


 * You could likely use AWB with a regular expression in order to express PAGENAME or at least to capture it in the find. Not sure on what it is you would use though.--


 * "PAGENAME" probably was a bad choice for my parameter name. This is just the name of the linked page, but not necessarily equal to.
 * @Godisme: What could that regex look like? The expressions don't have the same length... -- Weas-El ✉  15:15, November 3, 2011 (UTC)


 * I read some help pages now, but I wasn't able to figure out how to create an appropriate regular expression yet. It would be easier if the page title had always the same length. Do you know any experienced pywikipediabot users I could ask? -- Weas-El ✉  20:42, November 3, 2011 (UTC)

You might find the fixes.py script a useful source of advanced replacement examples. — Sovq 21:45, November 3, 2011 (UTC)


 * That means I'll have to write my own script for this? -- Weas-El ✉  22:31, November 3, 2011 (UTC)


 * That would be an option, yes, but instead of writing the whole script you can do what I do - change the replacement strings in one of the fixes.py functions (I usually modify the 'HTML' function) and the call fixes.py -FUNCTIONNAME though pywikipediabot. If you give links to a few pages which contain the string you want to replace, I could try and write an appropriate command to do the replacement. — Sovq 07:12, November 4, 2011 (UTC)


 * That would be a great help, thank you. I'm actually just beginning to learn using python. I've made use of the standard scripts before, but never changed their source code before yesterday.
 * You'll find a list of all pages in question here (all but user and user talk namespace). I'll be not at home for the next two days by the way, and probably won't log in during this time. -- Weas-El ✉  12:31, November 4, 2011 (UTC)

Ok, I think this should help: Add this: # Custom replacement 'lotr': { 'regex': True, 'msg': { 'en':u'Robot: Automated text replacement', },       'replacements': [ (r'(?i)\(.*?)\',             r""), ],   }, to the list of fixes in your fixes.py file. If you don't know where exactly, you can just replace this: fixes = { # These replacements will convert HTML to wiki syntax where possible, and with this: fixes = { # Custom replacement 'lotr': { 'regex': True, 'msg': { 'en':u'Robot: Automated text replacement', },       'replacements': [ (r'(?i)\(.*?)\',             r""), ],   },

# These replacements will convert HTML to wiki syntax where possible, and Then, run pywikipediabot and enter  where XXX.txt is a text file in the Python folder containing the list of pages on which you want to work on. I only tested if it would work on a few pages, so it might show errors on some pages, particularly the ones using special characters in the replacement strings, so you should pay attention if the bot doesn't break anything by accident. The  line will be the edit summary. Hope that helps, — Sovq 14:15, November 4, 2011 (UTC)


 * Thanks, I'll try it when I come back on sunday. -- Weas-El ✉  14:47, November 4, 2011 (UTC)


 * I had time to test it, and it works fine! There are some problems with special characters as you predicted, but I can handle the rest. Thanks a lot again. -- Weas-El ✉  21:22, November 4, 2011 (UTC)