[Pywikipedia-l] SVN: [6018] trunk/pywikipedia/wikipedia.py

filnik at svn.wikimedia.org filnik at svn.wikimedia.org
Sat Oct 25 13:03:52 UTC 2008


Revision: 6018
Author:   filnik
Date:     2008-10-25 13:03:52 +0000 (Sat, 25 Oct 2008)

Log Message:
-----------
New function that I will use in checkimages.py

Modified Paths:
--------------
    trunk/pywikipedia/wikipedia.py

Modified: trunk/pywikipedia/wikipedia.py
===================================================================
--- trunk/pywikipedia/wikipedia.py	2008-10-25 12:13:08 UTC (rev 6017)
+++ trunk/pywikipedia/wikipedia.py	2008-10-25 13:03:52 UTC (rev 6018)
@@ -913,6 +913,34 @@
             x = self.get()                
             return True # if we reach this point, we had no problems.
 
+    def getTemplates(self):
+        #action=query&prop=templates&titles=Main Page
+        """
+        Returns the templates that are used in the page given.
+
+        It works through the APIs.
+
+        If no templates found, returns None.
+        """
+        params = {
+            'action'    :'query',
+            'prop'      :'templates',
+            'titles'    :self.title(),
+            }
+
+        data = query.GetData(params,
+                        useAPI = True, encodeTitle = False)
+        pageid = data['query']['pages'].keys()[0]
+        try:
+            templates = data['query']['pages'][pageid]['templates']
+        except KeyError:
+            return None
+        templatesFound = list()
+        for template in templates:
+            templateName = template['title']
+            templatesFound.append(Page(self.site(), templateName))
+        return templatesFound
+
     def isRedirectPage(self):
         """Return True if this is a redirect, False if not or not existing."""
         try:





More information about the Pywikipedia-l mailing list