This forum is now read-only. Please use our new forums! Go to forums
What's wrong with this? can't pass 2.5
from urllib2 import urlopen
from json import load, dumps
url = ‘http://api.npr.org/query?apiKey=‘ key = ‘MDAxNzgzOTYyMDEyMTUwMDkyMDM1ZWUwYw001’ url += key url += ‘&numResults=1&requiredAssets=text,image,audio&format=json&id=1007’ response = urlopen(url) json_obj = load(response)
f = open(‘output.json’, ‘w’) f.write(dumps(json_obj, indent=4)) f.close()
for story in json_obj[‘list’][‘story’]:
print “TITLE: “ + story[‘title’][‘$text’] + “\n”
print “DATE: “ + story[‘storyDate’][‘$text’] + “\n”
print “TEASER: “ + story[‘teaser’][‘$text’] + “\n”
if ‘byline’ in story:
print “BYLINE: “ + story[‘byline’][0][‘name’][‘$text’] + “\n”
if ‘show’ in story:
print “PROGRAM: “ + story[‘show’][0][‘program’][‘$text’] + “\n”
if ‘link’ in story:
print “NPR URL: “ + story[‘link’][0][‘$text’]+”\n”
print “IMAGE: “ + story[‘image’][0][‘src’]+”\n”
if ‘caption’ in story[‘image’][0]:
print “IMAGE CAPTION: “+story[‘image’][‘caption’][‘$text’]+”\n”
if ‘producer’ in story[‘image’][0]:
print “IMAGE CREDIT: “+story[‘image’][‘producer’][‘$text’]+”\n”
print “MP3 AUDIO: “ + story[‘audio’][0][‘format’][‘mp3’][0][‘$text’]+”\n”
Answer 5182454fc200f38460003212
please use the ‘code indent button’ to format code as code:
Popular free courses
- Free Course
Learn SQL
In this SQL course, you'll learn how to manage large datasets and analyze real data using the standard data management language.Beginner friendly,4 LessonsLanguage Fluency - Free Course
Learn JavaScript
Learn how to use JavaScript — a powerful and flexible programming language for adding website interactivity.Beginner friendly,11 LessonsLanguage Fluency - Free Course
Learn HTML
Start at the beginning by learning HTML basics — an important foundation for building and editing web pages.Beginner friendly,6 LessonsLanguage Fluency