示例#1
0
    def _photoupload(self, filename):
        """Uploads picture to the pod.

        :param filename: path to picture file
        :type filename: str

        :returns: id of the photo being uploaded
        """
        data = open(filename, 'rb')
        image = data.read()
        data.close()

        params = {}
        params['photo[pending]'] = 'true'
        params['set_profile_image'] = ''
        params['qqfile'] = filename
        aspects = self._connection.getUserInfo()['aspects']
        for i, aspect in enumerate(aspects):
            params['photo[aspect_ids][{0}]'.format(i)] = aspect['id']

        headers = {
            'content-type': 'application/octet-stream',
            'x-csrf-token': repr(self._connection),
            'x-file-name': filename
        }

        request = self._connection.post('photos',
                                        data=image,
                                        params=params,
                                        headers=headers)
        if request.status_code != 200:
            raise errors.StreamError('photo cannot be uploaded: {0}'.format(
                request.status_code))
        return request.json()['data']['photo']['id']
示例#2
0
 def _obtain(self, max_time=0):
     """Obtains stream from pod.
     """
     params = {}
     if max_time: params['max_time'] = max_time
     request = self._connection.get(self._location, params=params)
     if request.status_code != 200:
         raise errors.StreamError('wrong status code: {0}'.format(
             request.status_code))
     return [Post(self._connection, post['id']) for post in request.json()]
示例#3
0
文件: streams.py 项目: lamby/diaspy
    def _obtain(self, max_time=0, suppress=True):
        """Obtains stream from pod.

        suppress:bool - suppress post-fetching errors (e.g. 404)
        """
        params = {}
        if max_time:
            params['max_time'] = max_time
            params['_'] = int(time.time() * 1000)
        request = self._connection.get(self._location, params=params)
        if request.status_code != 200:
            raise errors.StreamError('wrong status code: {0}'.format(
                request.status_code))
        posts = []
        for post in request.json():
            try:
                posts.append(Post(self._connection, guid=post['guid']))
            except errors.PostError:
                if not suppress:
                    raise
        return posts
示例#4
0
    def _obtain(self, max_time=0, suppress=True):
        """Obtains stream from pod.

		suppress:bool - suppress post-fetching errors (e.g. 404)
		"""
        params = {}
        if max_time:
            if self.latest == None:
                self.latest = int(time.mktime(time.gmtime()) * 1000)
                self.latest -= max_time
            else:
                self.latest += 1
            params['max_time'] = max_time
            params['_'] = self.latest
        request = self._connection.get(self._location, params=params)
        if request.status_code != 200:
            raise errors.StreamError('wrong status code: {0}'.format(
                request.status_code))
        posts = []
        latest_time = None  # Used to get the created_at from the latest posts we received.
        for post in request.json():
            try:
                comments = False
                if post['interactions']['comments_count'] > 3: comments = True
                posts.append(
                    Post(self._connection,
                         id=post['id'],
                         guid=post['guid'],
                         fetch=False,
                         comments=comments,
                         post_data=post))
                if post['created_at']: latest_time = post['created_at']
            except errors.PostError:
                if not suppress:
                    raise
        if latest_time:
            self.max_time = parse_utc_timestamp(latest_time)
        return posts