def send(self, acc, img, user, time=10): media_id = make_media_id(acc.username) r = acc._request('upload', { 'username': acc.username, 'media_id': media_id, 'type': 0 }, files={'data': encrypt(img.read())}) if len(r.content) != 0: raise Exception("Failed to upload snap.") acc.send(media_id, user, time=time)
def retry_post_story(self, data, caption="", time=10): """Post a snap to your story. Requires a data of the media :param data: The image/video data of the file to add to story :param caption: Not rendered by the receiver, but shows when looking at my stories in the authentic app :param time: The length of time to display on the story """ media_id = make_media_id(self.username) r = self._request('bq/retry_post_story', { 'username': self.username, 'timestamp': time() * 1000, 'media_id': media_id, 'client_id': media_id, 'caption_text_display': caption, 'zipped': int(is_zip(data)), 'type': get_media_type(data), 'time': time * 1000 }, files={'data': encrypt(data)}) return r.content
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) 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) r = self._request('upload', { 'username': self.username, 'media_id': media_id, 'type': media_type }, files={'data': encrypt(data)}) return media_id if len(r.content) == 0 else None
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) r = self._request('ph/upload', { 'username': self.username, 'media_id': media_id, 'type': media_type }, files={'data': encrypt(data)}) return media_id if len(r.content) == 0 else None