def generateKMLPlacemark(row,style): """ Return a valud KML placemark definition adding in data from the universal tags (description, website, etc.) """ name = row['name'] lon = row['lon'] lat = row['lat'] if (row['description']): description = row['description'] else: description = "<p>No further details known</p>" if (row['flickr']): pdata = flickr._doget('flickr.photos.getSizes', photo_id=row['flickr']) for psize in pdata.rsp.sizes.size: if (psize.label == 'Small'): description = "".join([description, """<p><img src="%s"></p>""" % (psize.source)]) if (row['operator']): description = "".join([description, """<p><strong>Operator:</strong> %s</p>""" % (row['operator'])]) if (row['website'] or row['wikipedia']): description = "".join([description, "<p><strong>More information:</strong> "]) if (row['website']): description = "".join([description, """<a href="%s">Website</a> """ % (row['website'])]) if (row['wikipedia']): row['wikipedia'] = re.sub(r'en:', '', row['wikipedia']) row['wikipedia'] = re.sub(r'http://en.wikipedia.org/wiki/', '', row['wikipedia']) description = "".join([description, """<a href="http://en.wikipedia.org/wiki/%s">Wikipedia article</a>""" % (row['wikipedia'])]) description = "".join([description, "</p>"]) return """<Placemark>\n\t<name>%s</name>\n\t<description><![CDATA[%s]]></description>\n\t<styleUrl>#%s</styleUrl>\n\t<Point>\n\t\t<coordinates>%s,%s</coordinates>\n\t</Point>\n</Placemark>\n""" % (name,description,style,lon,lat)
def photos_search_adv(user_id='', auth=False, tags='', tag_mode='', text='',\ min_upload_date='', max_upload_date='',\ min_taken_date='', max_taken_date='', \ license='', per_page='', page='', sort='',\ safe_search='', content_type='', extras = '', **kwargs): """Returns a list of Photo objects. If auth=True then will auth the user. Can see private etc """ method = 'flickr.photos.search' data = flickr._doget(method, auth=auth, user_id=user_id, tags=tags, text=text,\ min_upload_date=min_upload_date,\ max_upload_date=max_upload_date, \ min_taken_date=min_taken_date, \ max_taken_date=max_taken_date, \ license=license, per_page=per_page,\ page=page, sort=sort, safe_search=safe_search, \ content_type=content_type, \ tag_mode=tag_mode, \ extras=extras, **kwargs) photos = [] if data.rsp.photos.__dict__.has_key('photo'): if isinstance(data.rsp.photos.photo, list): for photo in data.rsp.photos.photo: photos.append(photo) else: photos = [data.rsp.photos.photo] return photos
def generateKMLPlacemark(row,style): """ Return a valud KML placemark definition adding in data from the universal tags (description, website, etc.) """ name = u'%s' % (row['name'].decode('utf-8')) name = name.encode('ascii', 'xmlcharrefreplace') lon = row['lon'] lat = row['lat'] description = '' cycle_link = "http://www.cyclestreets.net/journey/to/%s,%s,15/" % (lat, lon) walk_link = "http://maps.cloudmade.com/?lat=%s&lng=%s&zoom=15&directions=%s,%s&travel=foot&styleId=27911&opened_tab=1" % (lat, lon, lat, lon) travel_to_links = "<div class=\"travel\"><a href=\"%s\" target=\"_blank\"><img src=\"http://www.openecomaps.co.uk/images/cyclehere.png\" width=\"55\" height=\"45\" alt=\"Cycle here\" /></a> <a href=\"%s\" target=\"_blank\"><img src=\"http://www.openecomaps.co.uk/images/walkhere.png\" width=\"55\" height=\"45\" alt=\"Walk here\" /></a></div>" % (cycle_link, walk_link) description = "".join([description, travel_to_links]) if (row['description']): description = "".join([description, "<p>", u'%s' % (row['description']), "</p>"]) if (row['flickr']): pdata = flickr._doget('flickr.photos.getSizes', photo_id=row['flickr']) for psize in pdata.rsp.sizes.size: if (psize.label == 'Small'): description = "".join([description, """<p><img src="%s"></p>""" % (psize.source)]) if (row['operator']): description = "".join([description, """<p><strong>Operator:</strong> %s</p>""" % (row['operator'])]) if (row['website'] or row['wikipedia']): description = "".join([description, "<p><strong>More information:</strong> "]) if (row['website']): description = "".join([description, """<a href="%s">Website</a> """ % (row['website'])]) if (row['wikipedia']): row['wikipedia'] = re.sub(r'en:', '', row['wikipedia']) row['wikipedia'] = re.sub(r'http://en.wikipedia.org/wiki/', '', row['wikipedia']) description = "".join([description, """<a href="http://en.wikipedia.org/wiki/%s">Wikipedia article</a>""" % (row['wikipedia'])]) description = "".join([description, "</p>"]) return """<Placemark>\n\t<name>%s</name>\n\t<description><![CDATA[%s]]></description>\n\t<styleUrl>#%s</styleUrl>\n\t<Point>\n\t\t<coordinates>%s,%s</coordinates>\n\t</Point>\n</Placemark>\n""" % (name,description,style,lon,lat)
def getURL(photo, size, equal=False): method = 'flickr.photos.getSizes' data = flickr._doget(method, photo_id=photo.id) for psize in data.rsp.sizes.size: if psize.label == size: if equal and psize.width == psize.height: return psize.source elif not equal: return psize.source raise flickr.FlickrError, "No URL found"
def generateJSONFeature(row): ''' Return a valid GeoJSON feature definition adding in data from the universal tags (description, website, etc.) ''' try: test = row['popup_title'].decode('ascii') title = row['popup_title'] except UnicodeEncodeError: title = row['popup_title'].encode('ascii', 'xmlcharrefreplace') lon = row['lon'] lat = row['lat'] popupContents = '' cycle_link = 'http://www.cyclestreets.net/journey/to/%s,%s,15/' % (lat, lon) walk_link = 'http://maps.cloudmade.com/?lat=%s&lng=%s&zoom=15&directions=%s,%s&travel=foot&styleId=27911&opened_tab=1' % (lat, lon, lat, lon) travel_to_links = '<div class="travel"><a href="%s" target="_blank"><img src="http://www.openecomaps.co.uk/images/cyclehere.png" width="55" height="45" alt="Cycle here" /></a> <a href="%s" target="_blank"><img src="http://www.openecomaps.co.uk/images/walkhere.png" width="55" height="45" alt="Walk here" /></a></div>' % (cycle_link, walk_link) popupContents = ''.join([popupContents, travel_to_links]) if ('popup_contents' in row): popupContents = ''.join([popupContents, '<p>', u'%s' % (row['popup_contents']), '</p>']) if ('flickr' in row): try: pdata = flickr._doget('flickr.photos.getSizes', photo_id=row['flickr']) for psize in pdata.rsp.sizes.size: if (psize.label == 'Small'): popupContents = ''.join([popupContents, '''<p><img src="%s"></p>''' % (psize.source)]) except: pass if ('operator' in row): popupContents = ''.join([popupContents, '''<p><strong>Operator:</strong> %s</p>''' % (row['operator'])]) if ('website' in row or 'wikipedia' in row): popupContents = ''.join([popupContents, '<p><strong>More information:</strong> ']) if ('website' in row): popupContents = ''.join([popupContents, '''<a href="%s">Website</a> ''' % (row['website'])]) if ('wikipedia' in row): row['wikipedia'] = re.sub(r'en:', '', row['wikipedia']) row['wikipedia'] = re.sub(r'http://en.wikipedia.org/wiki/', '', row['wikipedia']) popupContents = "".join([popupContents, '''<a href="http://en.wikipedia.org/wiki/%s">Wikipedia article</a>''' % (row['wikipedia'])]) popupContents = ''.join([popupContents, '</p>']) feature = { "type":"Feature", "properties": { "name": title, "popupContent": popupContents, "icon": ''.join(['http://www.openecomaps.co.uk/feature_icons/', row['popup_style']]) }, "geometry": { "type": "Point", "coordinates": [row["lon"], row["lat"]] } } return feature
def getURL(photo, size, equal=False): """Retrieves a url for the photo. (flickr.photos.getSizes) photo - the photo size - what size 'Thumbnail, Small, Medium, Large, Original' equal - should width == height? """ method = 'flickr.photos.getSizes' data = flickr._doget(method, photo_id=photo.id) for psize in data.rsp.sizes.size: if psize.label == size: if equal and psize.width == psize.height: return psize.source elif not equal: return psize.source raise flickr.FlickrError, "No URL found"
def get_flickr_views(photo_id): method = 'flickr.photos.getInfo' data = flickr._doget(method, photo_id=photo_id) return int(data.rsp.photo.views)
def get_flickr_fav(photo_id): method = 'flickr.photos.getFavorites' data = flickr._doget(method, photo_id=photo_id) return int(data.rsp.photo.total)
def get_flickr_fav(user_id): method = 'flickr.people.getInfo' data = flickr._doget(method, user_id=user_id) return data.rsp.person.location.text
#!/usr/bin/env python import sys import urllib import pprint import flickr #photoData = flickr._doget('flickr.photos.getSizes', photo_id=3763496262) #for psize in photoData.rsp.sizes.size: # print psize.source, psize.label otherData = flickr._doget('flickr.photos.getInfo', photo_id=3763496262) u = flickr.User(otherData.rsp.photo.owner) print u.username
def _get_photo_url(self, photo, size="Medium"): method = 'flickr.photos.getSizes' data = flickr._doget(method, photo_id=photo.id) return self._get_resized(data, size) raise flickr.FlickrError, "No URL found"