Exemplo n.º 1
0
Arquivo: models.py Projeto: La0/beers
 def find_city(self):
   '''
   Find the city of a place, using it's coordinates
   and the CityFinder algorithm (fast)
   '''
   cf = CityFinder(self.get_point())
   city = cf.search()
   if city is not None:
     self.city = city
Exemplo n.º 2
0
  def import_place(self, venue, search_city):

    categories = self._categories.filter(foursquare_id__in=[c['id'] for c in venue['categories']])
    pos = (float(venue['location']['lat']), float(venue['location']['lng']))
    cf = CityFinder(pos)
    city = cf.search()
    if city is None:
      raise Exception('No city found')
    if city != search_city:
      print 'City mismatch search:"%s" vs. found:"%s"' % (search_city, city)

    location = geojson.Point(pos)

    defaults = {
      'name' : venue['name'],
      'city' : city,
      'creator' : self._user,
      'address' : venue['location'].get('address', ''),
      'geojson' : geojson.dumps(location),
    }
    place, created = Place.objects.get_or_create(foursquare_id=venue['id'], defaults=defaults)
    if not created:
      for k,v in defaults.items():
        setattr(place, k, v)
    place.find_subways()
    place.categories = categories
    print '%s place %d %s' % (created and 'Created' or 'Updated', place.id, place.name)

    # Add instagram
    try:
      res = self._instagram.location_search(foursquare_v2_id=place.foursquare_id)
      if not len(res):
        raise Exception('No instagram location found')
      location = res[0]
      place.instagram_id = location.id
      print 'Linked to instagram id %s' % (location.id,)
    except Exception, e:
      print 'Instagram failed: %s' % str(e)