Wikipedia:Bots/Requests for approval/Bot0612 6
- The following discussion is an archived debate. Please do not modify it. Subsequent comments should be made in a new section. The result of the discussion was Approved.
Automatic or Manually Assisted: Automatic supervised
Programming Language(s): python using pywikipedia
Function Summary: See here and also this BOTREQ.
Edit period(s): One-time run
Already has a bot flag (Y/N): Y
Function Details: The bot will get all pages that transclude {{Year in baseball}} (essentially all ‘fooyear in Baseball’ articles), and rename {{Year in baseball}} to {{Year in baseball top}}. The new template has no navigational sidebar; this will be replaced by a navbox (which will eventually reside at {{Year in baseball}}) which the bot will add to the bottom of each article. Although this process means that the articles will look a bit strange while the bot updates the templates, this will only be for ~10 minutes or so.
Discussion
[edit]- As always, feel free to take a look at the code. Richard0612 17:03, 23 January 2009 (UTC)[reply]
- Three critiques:
- It would probably be worthwhile to make sure of the template being replaced:
re.sub('\{\{(Template:)?Year in baseball(\s*[|}])', '{{Year in baseball top\g<2>', text)
(I couldn't get it to work with regex.Replace locally). - When inserting the
{{Template:Year in baseball}}
, you may as well leave out theTemplate:
. - It would be good to check whether the replacement has been done on the page already, just in case you run into errors and have to restart the bot. Otherwise it'll end up with
{{Year in baseball top}}{{Year in baseball}}
at the bottom of the article.
- It would probably be worthwhile to make sure of the template being replaced:
- You could also look into putting the
{{Year in baseball}}
above the category and interwiki links. Pywikipedia probably has a function to handle that sort of thing already. Anomie⚔ 01:30, 24 January 2009 (UTC)[reply]
- Three critiques:
- Spot on, as always, Anomie (one day I'll be able to write code with no holes in...). I've made the changes you recommended. pywikipedia doesn't have a way to insert text before categories/interwikis, so I wrote my own. It's hardly elegant, but it works. I put it in a separate file so that I can use it in other bot tasks; you can see it here. Richard0612 14:25, 24 January 2009 (UTC)[reply]
- I never manage to write code without holes either, I just have an eye for "how can this break" and I test everything I can think of. Your endofprose function has a major bug, though: any cross-namespace links (including File/Image links!) will falsely hit your regex, so the addition will be put just before the first image in the page. Something like this should be more robust, although I know little of python so it could probably be cleaned up a bit. And technically, "endofprose" is the wrong name, as the real end of prose would be above the "See also", "References", "External links", and navboxes. Anomie⚔ 19:11, 24 January 2009 (UTC)[reply]
- Spot on, as always, Anomie (one day I'll be able to write code with no holes in...). I've made the changes you recommended. pywikipedia doesn't have a way to insert text before categories/interwikis, so I wrote my own. It's hardly elegant, but it works. I put it in a separate file so that I can use it in other bot tasks; you can see it here. Richard0612 14:25, 24 January 2009 (UTC)[reply]
(Per request by Betacommand)
interwiki = wikipedia.getLanguageLinks(text)
categories = wikipedia.getCategoryLinks(text)
new_text = wikipedia.removeLanguageLinks(text)
new_text = wikipedia.removeCategoryLinks(text)
new_text += new_template
new_text = wikipedia.replaceLanguageLinks(new_text,interwiki)
new_text = wikipedia.replaceCategoryLinks(new_text,categories)
page.put(new_text,comment="fixing year of template")
If you wish to implement adding the template to the bottom, you should use a code like that, or something similar. Best, PeterSymonds (talk) 19:33, 24 January 2009 (UTC)[reply]
- I thought pywikipedia had some way to do it. Anomie⚔ 20:54, 24 January 2009 (UTC)[reply]
- (Note to self: test code more thoroughly in future) I can be incredibly stupid sometimes (they must never let me code anything for controlling nuclear power plants or suchlike...). I'll test out the method above for adding the template to the bottom of the article. I would have fixed that had I not tested it on an image-less test page. Thanks to both of you for fixing the massive bug! And I named the function 'endofprose' because 'beforecategoriesorinterwikis' is far too long to type! Richard0612 20:58, 24 January 2009 (UTC)[reply]
- OK, I've changed the code for the template insertion and tested it. It seems to work fine this time! It reorders the interwiki and category blocks, but this is arguably a good thing (cleaning up the general formatting). 21:51, 24 January 2009 (UTC)
- Approved for trial (25 edits). Please provide a link to the relevant contributions and/or diffs when the trial is complete. Anomie⚔ 22:38, 24 January 2009 (UTC)[reply]
- Thanks, I'll run the trial tomorrow when I can do the trial and the full run relatively quickly to avoid the articles looking weird for too long! Richard0612 23:06, 24 January 2009 (UTC)[reply]
- Trial complete. Everything seems fine, no problems encountered with the bot. Richard0612 12:22, 25 January 2009 (UTC)[reply]
- Thanks, I'll run the trial tomorrow when I can do the trial and the full run relatively quickly to avoid the articles looking weird for too long! Richard0612 23:06, 24 January 2009 (UTC)[reply]
- Approved for trial (25 edits). Please provide a link to the relevant contributions and/or diffs when the trial is complete. Anomie⚔ 22:38, 24 January 2009 (UTC)[reply]
- OK, I've changed the code for the template insertion and tested it. It seems to work fine this time! It reorders the interwiki and category blocks, but this is arguably a good thing (cleaning up the general formatting). 21:51, 24 January 2009 (UTC)
- (Note to self: test code more thoroughly in future) I can be incredibly stupid sometimes (they must never let me code anything for controlling nuclear power plants or suchlike...). I'll test out the method above for adding the template to the bottom of the article. I would have fixed that had I not tested it on an image-less test page. Thanks to both of you for fixing the massive bug! And I named the function 'endofprose' because 'beforecategoriesorinterwikis' is far too long to type! Richard0612 20:58, 24 January 2009 (UTC)[reply]
Approved. Looks good. Anomie⚔ 14:39, 25 January 2009 (UTC)[reply]
- The above discussion is preserved as an archive of the debate. Please do not modify it. Subsequent comments should be made in a new section.