nuevo pysweetter con xmlrpc. aƱadido sweet_show.py master
authorDaniel Garcia Moreno <dgarcia@emergya.es>
Wed, 1 Oct 2008 07:29:48 +0000 (09:29 +0200)
committerDaniel Garcia Moreno <dgarcia@emergya.es>
Wed, 1 Oct 2008 07:29:48 +0000 (09:29 +0200)
pysweetter.py

index 84a2077..2af45df 100644 (file)
@@ -1,47 +1,50 @@
-from SOAPpy import SOAPProxy
+from xmlrpclib import ServerProxy, Error
+import datetime
 
 class Comment:
     def __init__(self, sweet, user, avatar, created):
         self.sweet = sweet
         self.user = user
         self.avatar = avatar
-        self.created = created
+        self.created = datetime.datetime.fromtimestamp(created)
 
 class Sweetter:
     def __init__(self, apikey='', server='http://sweetter.net'):
         self.url = server
-        self.server = SOAPProxy(self.url + '/myservices/soap/')
+        self.server = ServerProxy(self.url + '/rpc/')
         self.apikey = apikey
 
     def autenticate(self, apikey):
         self.apikey = apikey
 
     def get_location(self, username):
-        return self.server.get_location(username=username)
+        return self.server.get_location(username)
 
     def set_location(self, location):
         if not self.apikey: raise Exception('No estas autenticado')
-        ret = self.server.set_location(location=location, apikey=self.apikey)
+        ret = self.server.set_location(locationself.apikey)
         if ret < 0:
             raise Exception('No se ha podido establecer la nueva localizacion')
 
     def post(self, comment):
         if not self.apikey: raise Exception('No estas autenticado')
-        ret = self.server.post(comment=comment, apikey=self.apikey)
+        ret = self.server.post(commentself.apikey)
 
         if ret < 0:
             raise Exception('No se ha podido hacer el post')
 
     def get_last_comments(self, username):
-        lista = self.server.get_last_comments(username=username)
+        lista = self.server.get_last_comments(username)
         
-        comments = [Comment(i.sweet, i.user, self.url + i.avatar, i.created) for i in lista.item]
+        comments = [Comment(i['sweet'], i['user'], self.url +\
+        i['avatar'], i['created']) for i in lista]
             
         return comments
 
     def get_last_followings(self, username):
-        lista = self.server.get_last_followings(username=username)
+        lista = self.server.get_last_followings(username)
 
-        comments = [Comment(i.sweet, i.user, self.url + i.avatar, i.created) for i in lista.item]
+        comments = [Comment(i['sweet'], i['user'], self.url +\
+        i['avatar'], i['created']) for i in lista]
             
         return comments