def stream(self, endpoint): url = urljoin(self.auth.url, endpoint) response = self.session.get(url, stream=True) response.raise_for_status() event = {} for line in response.iter_lines(): line = line.decode('utf-8') if not line: method_name = 'on_{event}'.format(event=event['event']) data = event['data'] if event['event'] == 'update': data = Status(json.loads(event['data'])) if event['event'] == 'notification': data = Notification(json.loads(event['data'])) method = operator.methodcaller(method_name, data) method(self.listener) event = {} continue if not line.startswith(':'): key, value = line.split(': ', 1) if key in event: event[key] += value else: event[key] = value
def get_status(self, toot_id): return Status(self.get('statuses/' + str(toot_id)))
def user_timeline(self, user_id, params={}): toots = self.get('accounts/' + str(user_id) + '/statuses') for i in range(0, len(toots)): toots[i] = Status(toots[i]) return toots
def public_timeline(self): toots = self.get('timelines/public') for i in range(0, len(toots)): toots[i] = Status(toots[i]) return toots
def home_timeline(self): toots = self.get('timelines/home') for i in range(0, len(toots)): toots[i] = Status(toots[i]) return toots
def favorites(self): toots = self.get('favourites') for i in range(0, len(toots)): toots[i] = Status(toots[i]) return toots
def destroy_favorite(self, toot_id): return Status(self.post('statuses/' + str(toot_id) + '/unfavourite', ))
def create_favorite(self, toot_id): return Status(self.post('statuses/' + str(toot_id) + '/favourite', ))
def unreblog(self, toot_id): return Status(self.post('statuses/' + str(toot_id) + '/unreblog', ))
def update_status_advanced(self, params): return Status(self.post('statuses', params))
def update_status(self, text): return Status(self.post('statuses', {'status': text}))