Lokal Profil has uploaded a new change for review. (
https://gerrit.wikimedia.org/r/370481 )
Change subject: Make unused image reports deal with sparql harvested data
......................................................................
Make unused image reports deal with sparql harvested data
Bug: T171300
Change-Id: I6197f30c318e11611d24c29a8ca9c45dc1134a80
---
M erfgoedbot/unused_monument_images.py
1 file changed, 20 insertions(+), 7 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/labs/tools/heritage
refs/changes/81/370481/1
diff --git a/erfgoedbot/unused_monument_images.py
b/erfgoedbot/unused_monument_images.py
index 951588d..74dadf4 100644
--- a/erfgoedbot/unused_monument_images.py
+++ b/erfgoedbot/unused_monument_images.py
@@ -72,10 +72,9 @@
monumentId = monumentId.upper()
if monumentId in withoutPhoto:
- m = re.search(
- '^[^\?]+\?title\=(.+?)&', withoutPhoto.get(monumentId))
try:
- wikiSourceList = m.group(1)
+ source_link = get_source_link(
+ countryconfig, monumentId, withoutPhoto)
except AttributeError:
pywikibot.warning(
u'Could not find wikiSourceList for %s (%s)' % (
@@ -83,12 +82,10 @@
continue
imageName = photos.get(catSortKey)
# pywikibot.output(u'Key %s returned a result' % (monumentId,))
- # pywikibot.output(wikiSourceList)
# pywikibot.output(imageName)
if totalImages <= maxImages:
- text += \
- u'File:%s|[[%s|%s]]\n' % (
- unicode(imageName, 'utf-8'), wikiSourceList,
monumentId)
+ text += u'File:{0}|{1}\n'.format(
+ unicode(imageName, 'utf-8'), source_link)
totalImages += 1
except ValueError:
pywikibot.warning(u'Got value error for %s' % (monumentId,))
@@ -114,6 +111,22 @@
return totalImages
+def get_source_link(countryconfig, monument_id, without_photo):
+ """Format the source as an appropriate wiki link."""
+ source = without_photo.get(monument_id)
+ if countryconfig.get('type') == 'sparql':
+ qid = source.split('/')[-1]
+ page_link = ':d:{0}'.format(qid)
+ else:
+ m = re.search('^[^\?]+\?title\=(.+?)&', source)
+ try:
+ page_link = m.group(1)
+ except AttributeError:
+ raise
+
+ return '[[{0}|{1}]]'.format(page_link, monument_id)
+
+
def getInterwikisUnusedImages(countrycode, lang):
result = u''
for (countrycode2, lang2), countryconfig in mconfig.countries.iteritems():
--
To view, visit https://gerrit.wikimedia.org/r/370481
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I6197f30c318e11611d24c29a8ca9c45dc1134a80
Gerrit-PatchSet: 1
Gerrit-Project: labs/tools/heritage
Gerrit-Branch: wikidata
Gerrit-Owner: Lokal Profil <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits