jenkins-bot has submitted this change and it was merged.

Change subject: (bug 62008) Added support for images Now with checking for 
redirect and if the image actually exists
......................................................................


(bug 62008) Added support for images
Now with checking for redirect and if the image actually exists

Change-Id: Id99cdea6581a4a5ccf9f810c60ed3a0c53127769
---
M scripts/harvest_template.py
1 file changed, 10 insertions(+), 0 deletions(-)

Approvals:
  Merlijn van Deen: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/scripts/harvest_template.py b/scripts/harvest_template.py
index 2507544..8b4d27c 100755
--- a/scripts/harvest_template.py
+++ b/scripts/harvest_template.py
@@ -145,6 +145,16 @@
                                             continue
                                 elif claim.getType() == 'string':
                                     claim.setTarget(value.strip())
+                                elif claim.getType() == 'commonsMedia':
+                                    commonssite = pywikibot.Site("commons", 
"commons")
+                                    imagelink = pywikibot.Link(value, 
source=commonssite, defaultNamespace=6)
+                                    image = pywikibot.ImagePage(imagelink)
+                                    if image.isRedirectPage():
+                                        image = 
pywikibot.ImagePage(image.getRedirectTarget())
+                                    if not image.exists():
+                                        pywikibot.output('[[%s]] doesn\'t 
exist so I can\'t link to it' % (image.title(),))
+                                        continue
+                                    claim.setTarget(image)
                                 else:
                                     pywikibot.output("%s is not a supported 
datatype." % claim.getType())
                                     continue

-- 
To view, visit https://gerrit.wikimedia.org/r/127478
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: Id99cdea6581a4a5ccf9f810c60ed3a0c53127769
Gerrit-PatchSet: 2
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Multichill <[email protected]>
Gerrit-Reviewer: Ladsgroup <[email protected]>
Gerrit-Reviewer: Merlijn van Deen <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
Pywikibot-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/pywikibot-commits

Reply via email to