Created
February 18, 2015 14:38
-
-
Save Vostbur/5ba5cde2b382ce8cfe14 to your computer and use it in GitHub Desktop.
Example auphonic API (get json)
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
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
import sys | |
import json | |
if sys.version_info < (3, 0, 0): | |
from codecs import open | |
try: | |
import requests | |
from requests.auth import HTTPBasicAuth | |
if int(requests.__version__.split('.')[0]) < 2: | |
if int(requests.__version__.split('.')[1]) < 12: | |
print("You may havo upgrade your python requests version!") | |
except: | |
print("Please install python requests!") | |
print("Instruction can be found here:") | |
print("http://docs.python-requests.org/en/latest/user/install/") | |
API_URL = "https://auphonic.com/api/productions.json" | |
def _write_json_data(): | |
username = "username" | |
password = "user_password" | |
headers = {"content-type": "application/json"} | |
filename = "dump.json" | |
req = requests.get(API_URL, headers=headers, auth=HTTPBasicAuth(str(username), str(password))) | |
p = json.loads(req.text) | |
j = json.dumps(p, sort_keys=True, indent=4, separators=(',', ': ')) | |
with open(filename, "w", encoding="utf-8") as f: | |
f.write(j) | |
def get_posts(): | |
filename = "dump.json" | |
with open(filename, "r", encoding="utf-8") as f: | |
p = json.loads(f.read()) | |
for i in p["data"]: | |
print(i["output_files"][0]["filename"]) | |
if __name__ == "__main__": | |
# _write_json_data() | |
get_posts() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment