def test_normalize_city_simple(): city = 'Los Angeles' res = address.normalize_city(city) eq(res, 'los angeles') city = 'L.A.' res = address.normalize_city(city) eq(res, 'la')
def test_normalize_city_empty(): city = '.,' res = address.normalize_city(city) eq(res, '')
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