Revision: 6840
Author: multichill
Date: 2009-05-06 11:48:12 +0000 (Wed, 06 May 2009)
Log Message:
-----------
pywikipediabot-Bugs-2787059 :
Stop the bot from crashing on bad titles.
Modified Paths:
--------------
trunk/pywikipedia/commonscat.py
Modified: trunk/pywikipedia/commonscat.py
===================================================================
--- trunk/pywikipedia/commonscat.py 2009-05-06 11:30:21 UTC (rev 6839)
+++ trunk/pywikipedia/commonscat.py 2009-05-06 11:48:12 UTC (rev 6840)
@@ -298,28 +298,30 @@
If the page doesnt exists the function will return None
'''
#wikipedia.output("getCommonscat: " + name );
- commonsPage = wikipedia.Page(wikipedia.getSite("commons", "commons"),
"Category:" + name);
- #This can throw a wikipedia.BadTitle, maybe convert this to catch
- #wikipedia.BadTitle
- #wikipedia.NoPage
- #wikipedia.IsRedirectPage
- if not commonsPage.exists():
- #wikipedia.output("getCommonscat : The category doesnt exist.");
- return u''
- elif commonsPage.isRedirectPage():
- #wikipedia.output("getCommonscat : The category is a redirect");
- return
checkCommonscatLink(commonsPage.getRedirectTarget().titleWithoutNamespace());
- elif "Category redirect" in commonsPage.templates():
- #wikipedia.output("getCommonscat : The category is a category
redirect");
- for template in commonsPage.templatesWithParams():
- if ((template[0]=="Category redirect") and (len(template[1]) > 0)):
- return checkCommonscatLink(template[1][0])
- elif commonsPage.isDisambig():
- #wikipedia.output("getCommonscat : The category is disambigu");
- return u''
- else:
- return commonsPage.titleWithoutNamespace()
+ try:
+ #This can throw a wikipedia.BadTitle
+ commonsPage = wikipedia.Page(wikipedia.getSite("commons", "commons"),
"Category:" + name);
+ if not commonsPage.exists():
+ #wikipedia.output("getCommonscat : The category doesnt exist.");
+ return u''
+ elif commonsPage.isRedirectPage():
+ #wikipedia.output("getCommonscat : The category is a redirect");
+ return
checkCommonscatLink(commonsPage.getRedirectTarget().titleWithoutNamespace());
+ elif "Category redirect" in commonsPage.templates():
+ #wikipedia.output("getCommonscat : The category is a category
redirect");
+ for template in commonsPage.templatesWithParams():
+ if ((template[0]=="Category redirect") and (len(template[1]) >
0)):
+ return checkCommonscatLink(template[1][0])
+ elif commonsPage.isDisambig():
+ #wikipedia.output("getCommonscat : The category is disambigu");
+ return u''
+ else:
+ return commonsPage.titleWithoutNamespace()
+ except wikipedia.BadTitle:
+ #Funky title so not correct
+ return u''
+
def main():
'''
Parse the command line arguments and get a pagegenerator to work on.
_______________________________________________
Pywikipedia-svn mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/pywikipedia-svn