source: subversion/applications/rendering/genericHeatmapRender/locationFinder_flickr_locations.py @ 30554

Last change on this file since 30554 was 16116, checked in by stevefaeembra, 10 years ago

initial version.. very basic heatmapping code using Python/Matplotlib?

File size: 2.6 KB
Line 
1# -*- coding: UTF8 -*-
2'''
3    This program is free software; you can redistribute it and/or modify
4    it under the terms of the GNU General Public License as published by
5    the Free Software Foundation; either version 2 of the License, or
6    (at your option) any later version.
7
8    This program is distributed in the hope that it will be useful,
9    but WITHOUT ANY WARRANTY; without even the implied warranty of
10    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11    GNU General Public License for more details.
12
13    You should have received a copy of the GNU General Public License along
14    with this program; if not, write to the Free Software Foundation, Inc.,
15    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
16'''
17
18
19import flickrapi
20from location import location
21import string
22from locationFinder import locationFinder
23
24# Enter your API key below
25api_key = '<enter your api key here>' 
26
27class locationFinder_flickr_locations(locationFinder):
28    '''
29    Responsible for generating a list of location objects
30    A series of location objects with (latitude/longitude/value)
31    '''
32   
33    assert api_key <> '<enter your api key here>', 'You need to set up a Flickr API key!'
34    flickr = flickrapi.FlickrAPI(api_key)
35       
36    def __init__(self):
37        '''
38        Constructor
39        '''
40       
41    def query(self,query,scope,debug=False):
42        '''
43        Flickr api query example
44        query should be a URL
45        e.g. United+States/New+York/New+York
46        scope should be one of
47        {country,region,county,location} etc.
48       
49        bbox should be a tuple (minlong,minlat,maxlong,maxlat)
50        if bbox not None, points are only added if inside the bounding box.
51        this is a kludge put in because flickr api sometimes includes outliers in error.
52       
53        '''
54        bbox=self.bounds
55        places = self.flickr.places_getInfoByUrl(url=query)
56        print "URL %s found successfully" % query
57        locality=places.find('.//place/%s' % scope)
58        woeid =  locality.get('woeid')
59        print "Finding children locations ..."
60        places=self.flickr.places_getChildrenWithPhotosPublic(woe_id=woeid)
61        for pl in places.find('places'):
62            name= (string.split(pl.text,","))[0]
63            latitude=float(pl.get('latitude'))
64            longitude=float(pl.get('longitude'))
65            count=int(pl.get('photo_count'))
66            if debug: print "%s has %d photos (%.2f,%.2f)" % (name,count,longitude,latitude)
67            self.addPoint(name,count,longitude,latitude)
68           
Note: See TracBrowser for help on using the repository browser.