def find_loc(description): words = description.split(' ') desc = ' '.join([w.capitalize() for w in words]) city = GeoText(description).cities country = GeoText(desc).country_mentions if city and country: return city[0], list(country.keys())[0] elif city and not country: return city[0], None, desc elif country and not city: return None, list(country.keys())[0] else: return None, None, desc
def retrieve_country(location_description): """ retrieve_country This static method consumes a plain-text description of a location and uses the geotext library to match it to a country. The best match is returned, if there were any (may return None). INPUTS: location_description OUTPUTS: country_code - 2-character ISO-Geocode """ if location_description in ["", None]: return None cdict = GeoText(location_description).country_mentions country_codes = list(cdict.keys()) return country_codes[0] if len(country_codes) > 0 else None
def countrysort(x): country = GeoText(x).country_mentions if len(country) != 0: result = list(country.keys()) return result[0]