Last active
August 29, 2015 14:06
-
-
Save Mixser/e8138b5caf75d4a86f97 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
EMAIL = "mike@razortheory.com" | |
PASSWORD = "123" | |
FILEPATH = "/home/mike/Music/sample.mp3" | |
# 1. Авторизуемся и получаем токен для дальнейших действий | |
r = requests.post("http://localhost:8000/api/signin", data={"email": EMAIL, "password": PASSWORD}) | |
result = r.json() | |
AUTH_TOKEN = result['token'] | |
headers = {} | |
headers["Authorization"] = "Token %s" % AUTH_TOKEN | |
# 2. Открываем файл для чтения и вставляем его содержимое в body request | |
file_content = open(FILEPATH).read() | |
r = requests.post("http://localhost:8000/api/save_recording", data=file_content, headers=headers) | |
print r.content | |
result = r.json() | |
record_id = result['trid'] | |
url_to_playback = result['url'] | |
url_to_ogg_file = result['ogg_url'] | |
url_to_mp4_file = result['mp4_url'] | |
# 3. Пока запись не подтверждена, ее прослушать нельзя. Подтверждаем ее | |
r = requests.get("http://localhost:8000/api/confirm_recording?trid=%s" % record_id, headers=headers) | |
if r.ok: | |
print "Success" | |
print "Playback url: ", url_to_playback | |
print "MP4 url: ", url_to_mp4_file | |
print "Ogg url: ", url_to_ogg_file |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment