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

filnik at svn.wikimedia.org filnik at svn.wikimedia.org
Thu May 22 14:36:01 UTC 2008


Revision: 5421
Author:   filnik
Date:     2008-05-22 14:36:01 +0000 (Thu, 22 May 2008)

Log Message:
-----------
getLatestUploader() added in the ImagePage class

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

Modified: trunk/pywikipedia/wikipedia.py
===================================================================
--- trunk/pywikipedia/wikipedia.py	2008-05-22 14:33:03 UTC (rev 5420)
+++ trunk/pywikipedia/wikipedia.py	2008-05-22 14:36:01 UTC (rev 5421)
@@ -131,7 +131,7 @@
 # longer needed.
 locale.setlocale(locale.LC_ALL, '')
 
-import config, login
+import config, login, query
 
 try:
     set # introduced in Python2.4: faster and future
@@ -2579,6 +2579,8 @@
         Return value is a list of tuples containing (timestamp, username,
         resolution, filesize, comment).
 
+        Currently not working
+
         """
         result = []
         history = re.search('(?s)<table class="filehistory">.+?</table>', self.getImagePageHtml())
@@ -2600,6 +2602,38 @@
                 result.append((datetime, username, resolution, size, comment))
         return result
 
+    def getLatestUploader(self):
+        """ Function that uses the APIs to detect the latest uploader of the image """
+        params = {
+            'action'    :'query',
+            'prop'      :'imageinfo',
+            'titles'    :self.title(),
+            }
+        data = query.GetData(params, useAPI = True, encodeTitle = False)
+        try:
+            # We don't know the page's id, if any other better idea please change it
+            pageid = data['query']['pages'].keys()[0]
+            nick = data['query']['pages'][pageid][u'imageinfo'][0]['user']
+            return nick
+        except IndexError:
+            raise NoPage(u'API Error, nothing found in the APIs')
+
+    def getLatestUploader(self):
+        """ Function that uses the APIs to detect the latest uploader of the image """
+        params = {
+            'action'    :'query',
+            'prop'      :'imageinfo',
+            'titles'    :self.title(),
+            }
+        data = query.GetData(params, useAPI = True, encodeTitle = False)
+        try:
+            # We don't know the page's id, if any other better idea please change it
+            pageid = data['query']['pages'].keys()[0]
+            nick = data['query']['pages'][pageid][u'imageinfo'][0]['user']
+            return nick
+        except IndexError:
+            raise NoPage(u'API Error, nothing found in the APIs')
+
     def getFileVersionHistoryTable(self):
         """Return the version history in the form of a wiki table."""
         lines = []





More information about the Pywikipedia-l mailing list