示例#1
0
文件: __init__.py 项目: bramgg/snapy
    def upload(self, path):
        """Upload media
        Returns the media ID on success. The media ID is used when sending
        the snap.
        """
        if not os.path.exists(path):
            raise ValueError('No such file: {0}'.format(path))

        with open(path, 'rb') as f:
            data = f.read()

        media_type = get_media_type(data)
        if media_type is None:
            raise ValueError('Could not determine media type for given data')

        media_id = make_media_id(self.username)
        now = str(timestamp())
        r = self._request('/ph/upload', {
            'media_id': media_id,
            'type': media_type,
            'timestamp': now,
            'username': self.username,
            'zipped': '0'
            }, {'now': now, 'gauth': self._get_gauth()}, files={'data': data})

        return media_id if len(r.content) == 0 else None
示例#2
0
    def upload(self, path):
        """Upload media
        Returns the media ID on success. The media ID is used when sending
        the snap.
        """
        if not os.path.exists(path):
            raise ValueError('No such file: {0}'.format(path))

        with open(path, 'rb') as f:
            data = f.read()

        media_type = get_media_type(data)
        if media_type is None:
            raise ValueError('Could not determine media type for given data')

        media_id = make_media_id(self.username)
        now = str(timestamp())
        r = self._request('/ph/upload', {
            'media_id': media_id,
            'type': media_type,
            'timestamp': now,
            'username': self.username,
            'zipped': '0'
        }, {
            'now': now,
            'gauth': self._get_gauth()
        },
                          files={'data': data})

        return media_id if len(r.content) == 0 else None
示例#3
0
文件: __init__.py 项目: A92hm/hackmit
    def upload_raw(self, data):
        """Upload media
        Returns the media ID on success. The media ID is used when sending
        the snap.
        """
        media_type = get_media_type(data)
        if media_type is None:
            raise ValueError('Could not determine media type for given data')

        media_id = make_media_id(self.username)
        now = str(timestamp())
        r = self._request('/ph/upload', {
            'media_id': media_id,
            'type': media_type,
            'timestamp': now,
            'username': self.username,
            'zipped': '0'
            }, {'now': now, 'gauth': self._get_gauth()}, files={'data': data})

        return media_id if len(r.content) == 0 else None