AƱadido pysweetter
authordanigm <danigm@arch_box>
Thu, 28 Aug 2008 21:18:54 +0000 (23:18 +0200)
committerdanigm <danigm@arch_box>
Thu, 28 Aug 2008 21:18:54 +0000 (23:18 +0200)
pysweetter.py [new file with mode: 0644]

diff --git a/pysweetter.py b/pysweetter.py
new file mode 100644 (file)
index 0000000..84a2077
--- /dev/null
@@ -0,0 +1,47 @@
+from SOAPpy import SOAPProxy
+
+class Comment:
+    def __init__(self, sweet, user, avatar, created):
+        self.sweet = sweet
+        self.user = user
+        self.avatar = avatar
+        self.created = created
+
+class Sweetter:
+    def __init__(self, apikey='', server='http://sweetter.net'):
+        self.url = server
+        self.server = SOAPProxy(self.url + '/myservices/soap/')
+        self.apikey = apikey
+
+    def autenticate(self, apikey):
+        self.apikey = apikey
+
+    def get_location(self, username):
+        return self.server.get_location(username=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)
+        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)
+
+        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)
+        
+        comments = [Comment(i.sweet, i.user, self.url + i.avatar, i.created) for i in lista.item]
+            
+        return comments
+
+    def get_last_followings(self, username):
+        lista = self.server.get_last_followings(username=username)
+
+        comments = [Comment(i.sweet, i.user, self.url + i.avatar, i.created) for i in lista.item]
+            
+        return comments