예제 #1
0
파일: stream.py 프로젝트: Python3pkg/Pawopy
    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
예제 #2
0
 def get_status(self, toot_id):
     return Status(self.get('statuses/' + str(toot_id)))
예제 #3
0
 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
예제 #4
0
 def public_timeline(self):
     toots = self.get('timelines/public')
     for i in range(0, len(toots)):
         toots[i] = Status(toots[i])
     return toots
예제 #5
0
 def home_timeline(self):
     toots = self.get('timelines/home')
     for i in range(0, len(toots)):
         toots[i] = Status(toots[i])
     return toots
예제 #6
0
 def favorites(self):
     toots = self.get('favourites')
     for i in range(0, len(toots)):
         toots[i] = Status(toots[i])
     return toots
예제 #7
0
 def destroy_favorite(self, toot_id):
     return Status(self.post('statuses/' + str(toot_id) + '/unfavourite', ))
예제 #8
0
 def create_favorite(self, toot_id):
     return Status(self.post('statuses/' + str(toot_id) + '/favourite', ))
예제 #9
0
 def unreblog(self, toot_id):
     return Status(self.post('statuses/' + str(toot_id) + '/unreblog', ))
예제 #10
0
 def update_status_advanced(self, params):
     return Status(self.post('statuses', params))
예제 #11
0
 def update_status(self, text):
     return Status(self.post('statuses', {'status': text}))