First you need to generate an APIKEY for you, you can do that on Flickr Developers page
After that you need to create a function to fetch the flickr API, generaly this is created in models, but you can do that in modules too.
Create a function in any of your model files
APIKEY = 'YOUR_API_KEY'
def get_flickerset(pset=None, per_page=15, page=1):
from urllib2 import urlopen
from xml.dom.minidom import parse as domparse
apiurl = 'http://api.flickr.com/services/rest/?method=flickr.photosets.getPhotos&api_key=%(apikey)s&photoset_id=%(pset)s&privacy_filter=1&per_page=%(per_page)s&page=%(page)s&extras=url_t,url_m,url_o,url_sq'
dom = domparse(urlopen(apiurl % dict(pset=pset, per_page=per_page, page=page, apikey=APIKEY)))
photos = []
for node in dom.getElementsByTagName('photo'):
photos.append({
'id':node.getAttribute('id'),
'title':node.getAttribute('title'),
'thumb':node.getAttribute('url_t'),
'medio':node.getAttribute('url_m'),
'original':node.getAttribute('url_o'),
'square':node.getAttribute('url_sq'),
})
return photos
Now you can call that funtion from controller or views:
def testflickr():
photos=get_flickerset(pset='THE_PHOTOSET_ID', per_page=15, page=1)
return locals()
In view do that
{{for photo in photos:}}
{{=IMG(_src=photo['square'])}}
{{pass}}
The final
Comments (0)