Esempio n. 1
0
def _guessYelpId(placeName, lat, lon):
    safePlaceId = hashlib.md5(placeName).hexdigest()
    cachedId = db.child(eventsTable).child("cache/" + safePlaceId).get().val()
    if cachedId:
        return cachedId

    opts = {
      # 'term': placeName, # Yelp does a bad job with term searching
      'limit': 20,
      #'radius_filter': 1000,
      #'sort_by': 'distance',
      'sort': 1,
    }
    r = yelpClient.search_by_coordinates(lat, lon, **opts)
    if len(r.businesses) > 0:
        location = (lat, lon)
        businessesWithCoords = filter(
            lambda b:
                (b.location is not None) and (b.location.coordinate is not None),
            r.businesses)
        biz = min(businessesWithCoords, key=lambda b:
            geo.distance(location,
                         (b.location.coordinate.latitude, b.location.coordinate.longitude))
        )
        log.debug("%s --> %s" % (placeName, biz.name))
        researchVenue(biz)

        # Add bizId to cache
        record = { "cache/" +  safePlaceId: str(biz.id) }
        db.child(eventsTable).update(record)

        return biz.id
    else:
        log.info("Can't find %s" % placeName)
        return None
Esempio n. 2
0
def _getVenuesFromIndex(lat, lon):
    opts = {
      "radius_filter": 25000,
      "sort": 1,
      "limit": 20, 
      "offset": 0, 
      "category_filter": CATEGORIES
    }
    return yelpClient.search_by_coordinates(lat, lon, **opts)
Esempio n. 3
0
def _singleSearchAPIQuery(lat, lon, radius, sortOrder, offset):
    opts = {
        "radius_filter": radius,
        "sort": sortOrder,
        "limit": YELP_MAX_PER_PAGE,
        "offset": offset,
        "category_filter": CATEGORIES
    }
    return yelpClient.search_by_coordinates(lat, lon, **opts)
Esempio n. 4
0
def _guessYelpId(placeName, lat, lon):
    opts = {
      'term': placeName[:30],
      'limit': 1
    }
    r = yelpClient.search_by_coordinates(lat, lon, **opts)
    if len(r.businesses) > 0:
        return r.businesses[0].id
    else:
        return None
Esempio n. 5
0
def _getVenuesFromIndex(lat, lon, offset=0, radius=40000):
    radius = min(radius, 40000)
    opts = {
        "radius_filter": radius,  # max 40000
        "sort": 1,  # 1 = by distance, 2 = bayesian by rating.
        "limit": 20,
        "offset": offset,
        "category_filter": CATEGORIES
    }
    return yelpClient.search_by_coordinates(lat, lon, **opts)
Esempio n. 6
0
def _singleSearchAPIQuery(lat, lon, offset, radius, sortOrder):
    radius = min(radius, 40000)
    opts = {
        "radius_filter": radius,
        "sort_by": sortOrder,
        "limit": 20,
        "offset": offset,
        "category_filter": CATEGORIES
    }
    return yelpClient.search_by_coordinates(lat, lon, **opts)
Esempio n. 7
0
def _guessYelpId(placeName, lat, lon):
    safePlaceName = placeName.replace(".", "_")
    cachedId = db.child(eventsTable).child("cache/" +
                                           safePlaceName).get().val()
    if cachedId:
        return cachedId

    opts = {'term': placeName[:30], 'limit': 1}
    r = yelpClient.search_by_coordinates(lat, lon, **opts)
    if len(r.businesses) > 0:
        biz = r.businesses[0]
        researchVenue(biz)

        # Add bizId to cache
        record = {"cache/" + safePlaceName: str(biz.id)}
        db.child(eventsTable).update(record)

        return biz.id
    else:
        return None
Esempio n. 8
0
def getLocality(lat, lon, **kwargs):
    return yelpClient.search_by_coordinates(lat, lon, **kwargs)