Skip to content

Instantly share code, notes, and snippets.

@deidyomega
Last active October 3, 2015 02:58
Show Gist options
  • Save deidyomega/67396053adeb01cb9f20 to your computer and use it in GitHub Desktop.
Save deidyomega/67396053adeb01cb9f20 to your computer and use it in GitHub Desktop.
import requests
key = "API_KEY_HERE"
def getNPR(zipcode, key):
url = "http://api.npr.org/stations?apiKey={0}&format=json&zip={1}".format(key, zipcode)
r = requests.get(url)
return r.json()
def parse_station_json(json_obj):
print "=-=-=-=-=-=-=-=-=-=-=-=-=-=-"
for station in json_obj['station']:
print station['callLetters']['$text'] + ": " + station['marketCity']['$text'] + ", " + station['state']['$text']
print "Frequency: " + station['frequency']['$text'] + " " + station['band']['$text']
if 'url' in station:
print "MP3 Streams: "
for link in station['url']:
if link["type"] == "Audio MP3 Stream":
print "\t" + link["title"] + " - " + link["$text"]
print "=-=-=-=-=-=-=-=-=-=-=-=-=-=-"
json_obj = getNPR('85016', key)
parse_station_json(json_obj)
import requests
def search(title):
# Web API that allows searching for movies
url = "http://www.omdbapi.com/?t={0}&plot=short&r=json".format(title)
# This sends the request, and puts the result in the variable "r"
r = requests.get(url)
# This converts the JSON object into a python dictionary (same as obj in JS)
movie = r.json()
for item in movie:
print "Key: {0}\nValue: {1}\n\n".format(item, movie[item])
search("Frozen")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment