class Sweetter: def __init__(self, apikey='', server='http://sweetter.net'): self.url = server 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) def set_location(self, location): if not self.apikey: raise Exception("You aren't authenticated") ret = self.server.set_location(location, self.apikey) if ret < 0: raise Exception("Can't set location, I don't know why") def post(self, comment): if not self.apikey: raise Exception("You aren't authenticated") ret = self.server.post(comment, self.apikey) if ret < 0: raise Exception("Can't post, I don't know why") def get_last_comments(self, username): return self.get_something(username, self.server.get_last_comments) def get_replies(self, username): return self.get_something(username, self.server.get_replies) def get_last_followings(self, username): return self.get_something(username, self.server.get_last_followings) def get_TODO_list(self, username): return self.get_something(username, self.server.get_TODO_list) def get_something(self, username, func): lista = func(username) comments = [Comment(i['sweet'], i['user'], self.url +\ i['avatar'], i['created']) for i in lista] return comments