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

Change subject: Process template redirects correctly
......................................................................


Process template redirects correctly

Also strip the template parameters so any whitespace
doesn't get in the way. Minor PEP8 fixes too.

Change-Id: I04206f6ebd901d649ff9c12d49e8e7f37f2f8d6d
---
M scripts/harvest_template.py
1 file changed, 20 insertions(+), 3 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 d4bef05..2bc5ace 100755
--- a/scripts/harvest_template.py
+++ b/scripts/harvest_template.py
@@ -49,9 +49,9 @@
         self.setSource(pywikibot.Site().language())
 
     def setSource(self, lang):
-        '''
+        """
         Get the source
-        '''
+        """
         page = pywikibot.Page(self.repo, 'Wikidata:List of wikis/python')
         source_values = json.loads(page.get())
         source_values = source_values['wikipedia']
@@ -66,8 +66,23 @@
         """
         Starts the robot.
         """
+        self.templateTitles = self.getTemplateSynonyms(self.templateTitle)
         for page in self.generator:
             self.procesPage(page)
+
+    def getTemplateSynonyms(self, title):
+        """
+        Fetches redirects of the title, so we can check against them
+        """
+        pywikibot.output('Finding redirects...')  # Put some output here since 
it can take a while
+        temp = pywikibot.Page(pywikibot.Site(), title, ns=10)
+        if temp.isRedirectPage():
+            temp = temp.getRedirectTarget()
+        titles = [page.title(withNamespace=False)
+                  for page
+                  in temp.getReferences(redirectsOnly=True, namespaces=[10], 
follow_redirects=False)]
+        titles.append(temp.title(withNamespace=False))
+        return titles
 
     def procesPage(self, page):
         """
@@ -83,8 +98,10 @@
             templates = pywikibot.extract_templates_and_params(pagetext)
             for (template, fielddict) in templates:
                 # We found the template we were looking for
-                if template.replace(u'_', u' ') == self.templateTitle:
+                if template.replace(u'_', u' ') in self.templateTitles:
                     for field, value in fielddict.items():
+                        field = field.strip()
+                        value = value.strip()
                         # This field contains something useful for us
                         if field in self.fields:
                             # Check if the property isn't already set

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

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

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

Reply via email to