def test_normalize_street_street_abbrev(): street = '2970 N. Swan Rd at Ft. Lowell' res = address.normalize_street(street) eq(res, '2970 n swan rd at ft lowell') street = '1716 NORTH CAHUENGA BOULEVARD,' res = address.normalize_street(street) eq(res, '1716 n cahuenga blvd') street = '1448 Gower St. (On The Corner Of Sunset Blvd)' res = address.normalize_street(street) eq(res, '1448 gower st on the cor of sunset blvd')
def test_normalize_street_cardinal_abbrev(): street = '2970 N. Swan' res = address.normalize_street(street) eq(res, '2970 n swan') street = '1716 NORTH CAHUENGA,' res = address.normalize_street(street) eq(res, '1716 n cahuenga') street = '555 MAIN SOUTHEAST' res = address.normalize_street(street) eq(res, '555 main se') street = '555 northwest broadway' res = address.normalize_street(street) eq(res, '555 nw broadway')
def test_normalize_street_empty(): street = '.,' res = address.normalize_street(street) eq(res, '')
def test_normalize_street_street_abbrev_in_word(): street = '555 Falley Boulevard)' res = address.normalize_street(street) eq(res, '555 falley blvd')
def test_normalize_street_cardinal_abbrev_in_word(): street = '2970 N. Least' res = address.normalize_street(street) eq(res, '2970 n least')
def test_normalize_street_simple(): street = '2970 Swan Rd.,' res = address.normalize_street(street) eq(res, '2970 swan rd')
def _match_with_venue(event, _log=None): if _log is None: _log = log facebook = event["facebook"] name = facebook.get("location") if name is None: name = facebook["owner"]["name"] venue = facebook["venue"] address = normalize_street(venue["street"]) locality = normalize_city(venue["city"]) region = normalize_state(venue.get("state", "")) country = normalize_country(venue.get("country", "")) if not address or not locality: _log.debug("Event {event_id} has invalid address or locality. " "Skipping.".format(event_id=event["_id"])) return None address = address.title() locality = locality.title() latitude = venue["latitude"] longitude = venue["longitude"] # coordinates of type int are too ambigious to be considered # good if type(latitude) is not float or type(longitude) is not float: _log.debug("Event {event_id} has invalid latitude or longitude. " "Skipping.".format(event_id=event["_id"])) return None # coordinates with little precision are too ambigious to be # considered good lat_precision = Decimal(repr(latitude)) lng_precision = Decimal(repr(longitude)) lat_precision = lat_precision.as_tuple().exponent lng_precision = lng_precision.as_tuple().exponent if lat_precision > -5 or lng_precision > -5: _log.debug( "Event {event_id} has latitude or longitude with " "little precision. Skipping.".format(event_id=event["_id"]) ) return None match = OrderedDict( [ ( "ubernear", OrderedDict([("place_id", event["_id"]), ("source", "facebook"), ("location", [longitude, latitude])]), ), ( "place", OrderedDict( [ ("address", address), ("locality", locality), ("name", name), ("latitude", latitude), ("longitude", longitude), ] ), ), ] ) if region: region = region.upper() match["place"]["region"] = region if country: country = country.upper() match["place"]["country"] = country return match