Reputation: 1
if i use 0 instead of x ( in the while loop) the program works and i get the 1st photo from someone's favorite list from flickr but if i want more than or other than the 1st photo i get this error
import flickrlib
import webbrowser
FLICKR_API_KEY = "f86203e922041a6a999fd4a59f19b1e6"
FLICKR_API_SSECRET = "b286bcaddafb00c8"
flickruser = raw_input("Who are you interested in? ")
amount = int(raw_input("How many pictures would you like to see? "))
total = amount
counter = 0
imagepile = ""
x= 0
client = flickrlib.FlickrAgent(FLICKR_API_KEY, FLICKR_API_SSECRET)
person = client.flickr.people.findByUsername( username= flickruser)
userid = person[u'id']
photos = client.flickr.favorites.getPublicList(user_id= userid, per_page=1)
while counter < total:
farm = photos[u'photo'] [x] [u'farm']
server = photos[u'photo'] [x] [u'server']
photo_id = photos[u'photo'] [x] [u'id']
secret = photos[u'photo'] [x] [u'secret']
imgsrc = "<img src='http://farm" + farm + ".static.flickr.com/" + server + "/" + photo_id + "_" + secret +".jpg' /><br />"
imagepile = imagepile + imgsrc
counter= counter+1
x=x+1
htmlopen = "<html><head><title>"+ flickruser + "</title></head><body><h1>" + flickruser + "'s Public List. ""</h1>"
simple_page = htmlopen + imagepile + "</body></html>"
xml_file = open("webpage.html", "w")
xml_file.write(simple_page)
xml_file.close()
webbrowser.open("webpage.html")
Upvotes: 0
Views: 181
Reputation: 137282
Because you use per_page=1
here:
photos = client.flickr.favorites.getPublicList(user_id= userid, per_page=1)
and you get only one photo.
Upvotes: 3
Reputation: 25303
I don't know Flickr's API, but it looks like you're only asking for 1 photo in getPublicList
. Either way, you're not checking to make sure that total
is less than the number of pictures returned from getPublicList
.
Upvotes: 5