-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlocations.py
53 lines (45 loc) · 1.86 KB
/
locations.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import re
COUNTRIES = [
"United States", "Canada", "Mexico", "Brazil", "Argentina",
"United Kingdom", "France", "Germany", "Italy", "Spain",
"China", "Japan", "India", "Russia", "Australia",
"South Africa", "Egypt", "Nigeria", "Kenya", "Saudi Arabia",
"South Korea", "Indonesia", "Vietnam", "Philippines", "Turkey",
"Pakistan", "Bangladesh", "Iran", "Thailand", "Malaysia"
]
CONTINENTS = [
"Africa", "Antarctica", "Asia", "Europe", "North America",
"Oceania", "South America"
]
CITIES = [
"New York", "Los Angeles", "Chicago", "Houston", "Phoenix",
"Philadelphia", "San Antonio", "San Diego", "Dallas", "San Jose",
"Toronto", "Vancouver", "Montreal", "Calgary", "Ottawa",
"London", "Paris", "Berlin", "Madrid", "Rome",
"Beijing", "Shanghai", "Tokyo", "Mumbai", "Delhi",
"Sydney", "Melbourne", "Brisbane", "Perth", "Auckland"
]
DISTRICTS = [
"Brooklyn", "Manhattan", "Queens", "Bronx", "Staten Island",
"Central", "Western", "Eastern", "Southern", "Northern",
"Downtown", "Midtown", "Uptown", "East Side", "West Side",
"California"
]
def normalize_string(s):
return re.sub(r'[^\w\s]', '', s).strip().lower()
def is_country_or_location(name):
normalized_name = normalize_string(name)
normalized_countries = [normalize_string(country) for country in COUNTRIES]
normalized_continents = [normalize_string(continent) for continent in CONTINENTS]
normalized_cities = [normalize_string(city) for city in CITIES]
normalized_districts = [normalize_string(district) for district in DISTRICTS]
if normalized_name in normalized_countries:
return True
elif normalized_name in normalized_continents:
return True
elif normalized_name in normalized_cities:
return True
elif normalized_name in normalized_districts:
return True
else:
return False