This forum is now read-only. Please use our new forums at discuss.codecademy.com.

The NPR API Forum

View Course » View Exercise

333 points
1013c216dd8158f07aac077f40eec9b0?s=140&d=retro
Submitted by
Oymedkatter
over 3 years ago

I don't understand what to do in this exercise

I totally have no idea of what to do.

Here is the exercise :

Edit the url we use to call the API.

Change the output format to rss.

Instead of requiring stories with audio, require stories with text.

Hit Save & Submit Code and follow the prompts to output your valid RSS feed XML.

The hint only talks about something with text.

My code:

from urllib2 import urlopen
from urllib import quote

key = "API_KEY"
url = 'http://api.npr.org/query?apiKey='
url += key + '&numResults=3&action=or&requiredAssets=audio&format=Podcast'

nprid = rawinput("Enter comma-separated NPR IDs or leave blank." )
searchstring = rawinput("Enter your search string or leave blank.")
feedtitle = rawinput("What's your feed title?")

if nprid or searchstring:
rawinput("Hit Enter to download your podcast.")
if npr
id:
url = url + "&id=" + nprid
if search
string:
url = url + "&searchTerm=" + quote(searchstring)
if feed
title:
url = url + "&title="
response = urlopen(url)
output = response.read()
myfeed = open('myfeed.xml', 'w')
myfeed.write(output)
my
feed.close()
else:
raw_input("You must enter an NPR ID, a search term, or both.")

Do anyone have any idea of what to do?


0 votes

permalink

I got past this part but I wasn't sure if I was correct (sometimes it lets me pass without my answer being correct).

What I did was in the line
url += key + '&numResults=3&action=or&requiredAssets=audio&format=Podcast'
I changed requiredAssets=text and format=rss
Also my "or" used a capital o "Or" but I don't know if that matters at all.

1660 points
B5f39333a173dfc4dcd307ee5dcd2dd6?s=140&d=retro
Submitted by
phippsjr89
over 3 years ago