Jean-Frédéric has uploaded a new change for review.
https://gerrit.wikimedia.org/r/236424
Change subject: Fix bug in exception handling
......................................................................
Fix bug in exception handling
Change-Id: I83c126087b355b5851024285a0678d55408aee68
---
M erfgoedbot/categorize_images.py
1 file changed, 7 insertions(+), 10 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/labs/tools/heritage
refs/changes/24/236424/1
diff --git a/erfgoedbot/categorize_images.py b/erfgoedbot/categorize_images.py
index 0ac4e40..47de39c 100644
--- a/erfgoedbot/categorize_images.py
+++ b/erfgoedbot/categorize_images.py
@@ -25,7 +25,7 @@
class
NoMonumentIdentifierFoundException(pywikibot.exceptions.PageRelatedError):
- message = u"No Monument Identifier could be found"
+ message = u"No Monument Identifier could be found for %s"
pass
@@ -251,39 +251,37 @@
pywikibot.output(u'Unable to extract a valid id')
break
if not monumentId:
- raise NoMonumentIdentifierFoundException
+ raise NoMonumentIdentifierFoundException(page)
return monumentId
def get_new_categories(monumentId, monData, lang, commonsCatTemplates):
(monumentName, monumentCommonscat,
monumentArticleTitle, monumentSource) = monData
+ commons_site = pywikibot.Site(u'commons', u'commons')
newcats = []
# First try to add a category based on the commonscat field in the list
if monumentCommonscat:
# Might want to include some error checking here
- site = pywikibot.Site(u'commons', u'commons')
try:
- cat = pywikibot.Category(site, monumentCommonscat)
+ cat = pywikibot.Category(commons_site, monumentCommonscat)
newcats.append(cat)
except ValueError:
pywikibot.output(u'The Commonscat field for %s contains an invalid
category %s' % (
monumentId, monumentCommonscat))
-
# Option two is to use the article about the monument and see if it has
# Commonscat links
if not newcats:
monumentArticle = None
if monumentArticleTitle:
- site = pywikibot.Site(lang, u'wikipedia')
- monumentArticle = pywikibot.Page(site, monumentArticleTitle)
-
+ project_site = pywikibot.Site(lang, u'wikipedia')
+ monumentArticle = pywikibot.Page(project_site,
monumentArticleTitle)
if monumentArticle:
if monumentArticle.isRedirectPage():
monumentArticle = monumentArticle.getRedirectTarget()
try:
for commonsCatTemplateName in commonsCatTemplates:
- commonsCatTemplate = pywikibot.Page(site, 'Template:%s' %
commonsCatTemplateName)
+ commonsCatTemplate = pywikibot.Page(project_site,
'Template:%s' % commonsCatTemplateName)
if commonsCatTemplate in monumentArticle.templates():
newcats = []
newcats.append(
@@ -291,7 +289,6 @@
except pywikibot.SectionError:
pywikibot.output(u'Incorrect redirect at %s' %
(monumentArticle.title(),))
-
# Option three is to see if the list contains Commonscat links (whole list)
if not newcats:
monumentList = getList(lang, monumentSource)
--
To view, visit https://gerrit.wikimedia.org/r/236424
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I83c126087b355b5851024285a0678d55408aee68
Gerrit-PatchSet: 1
Gerrit-Project: labs/tools/heritage
Gerrit-Branch: master
Gerrit-Owner: Jean-Frédéric <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits