Revision: 7462
Author:   filnik
Date:     2009-10-14 16:29:25 +0000 (Wed, 14 Oct 2009)

Log Message:
-----------
Bugfix: getTemplates(), when there aren't templates it crashed, now no more

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

Modified: trunk/pywikipedia/wikipedia.py
===================================================================
--- trunk/pywikipedia/wikipedia.py      2009-10-14 16:22:04 UTC (rev 7461)
+++ trunk/pywikipedia/wikipedia.py      2009-10-14 16:29:25 UTC (rev 7462)
@@ -1054,14 +1054,15 @@
         while True:
             data = query.GetData(params, self.site(), encodeTitle = False)
             pageid = data[u'query'][u'pages'].keys()[0]
-            for tmp in data['query']['pages'][pageid].values()[0]:
-                count += 1
-                try:
-                    tmpsFound.append(Page(self.site(), tmp['title'], 
defaultNamespace=tmp['ns']) )
-                except TypeError:
-                    pass
-                if count >= tllimit:
-                    break
+            if type(data['query']['pages'][pageid].values()[0]) == list(): # 
if it's not a list: no templates
+                for tmp in data['query']['pages'][pageid].values()[0]:
+                    count += 1
+                    try:
+                        tmpsFound.append(Page(self.site(), tmp['title'], 
defaultNamespace=tmp['ns']) )
+                    except TypeError: # no templates in the file.
+                        pass
+                    if count >= tllimit:
+                        break
             
             if 'query-continue' in data and count < tllimit:
                 params["tlcontinue"] = 
data["query-continue"]["templates"]["tlcontinue"]



_______________________________________________
Pywikipedia-svn mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/pywikipedia-svn

Reply via email to