|
@@ -1,8 +1,18 @@
|
|
|
+import random
|
|
|
+
|
|
|
import requests
|
|
|
|
|
|
from .shared import point_has_streetview, GeoPointSource, CachedGeoPointSource, ExhaustedSourceError, GeoPointSourceGroup
|
|
|
|
|
|
RSV_URL = "https://randomstreetview.com/data"
|
|
|
+VALID_COUNTRIES = ("ad", "au", "ar", "bd", "be", "bt", "bw",
|
|
|
+ "br", "bg", "kh", "ca", "cl", "hr", "co",
|
|
|
+ "cz", "dk", "ae", "ee", "fi", "fr", "de",
|
|
|
+ "gr", "hu", "hk", "is", "id", "ie", "it",
|
|
|
+ "il", "jp", "lv", "lt", "my", "mx", "nl",
|
|
|
+ "nz", "no", "pe", "pl", "pt", "ro", "ru",
|
|
|
+ "sg", "sk", "si", "za", "kr", "es", "sz",
|
|
|
+ "se", "ch", "tw", "th", "ua", "gb", "us")
|
|
|
|
|
|
|
|
|
def call_random_street_view(country_lock=None):
|
|
@@ -13,8 +23,10 @@ def call_random_street_view(country_lock=None):
|
|
|
|
|
|
This function calls the streetview metadata endpoint - there is no quota consumed.
|
|
|
"""
|
|
|
+ if country_lock is None:
|
|
|
+ country_lock = random.choice(VALID_COUNTRIES)
|
|
|
try:
|
|
|
- rsv_js = requests.post(RSV_URL, data={"country": country_lock.lower() if country_lock is not None else "all"}).json()
|
|
|
+ rsv_js = requests.post(RSV_URL, data={"country": country_lock.lower()}).json()
|
|
|
except:
|
|
|
return []
|
|
|
|
|
@@ -22,7 +34,7 @@ def call_random_street_view(country_lock=None):
|
|
|
return []
|
|
|
|
|
|
return [
|
|
|
- (point["lat"], point["lng"])
|
|
|
+ (country_lock, point["lat"], point["lng"])
|
|
|
for point in rsv_js["locations"]
|
|
|
if point_has_streetview(point["lat"], point["lng"])
|
|
|
]
|
|
@@ -48,14 +60,6 @@ class RSVPointSource(GeoPointSource):
|
|
|
|
|
|
|
|
|
WORLD_SOURCE = CachedGeoPointSource(RSVPointSource(), 10)
|
|
|
-VALID_COUNTRIES = ("ad", "au", "ar", "bd", "be", "bt", "bw",
|
|
|
- "br", "bg", "kh", "ca", "cl", "hr", "co",
|
|
|
- "cz", "dk", "ae", "ee", "fi", "fr", "de",
|
|
|
- "gr", "hu", "hk", "is", "id", "ie", "it",
|
|
|
- "il", "jp", "lv", "lt", "my", "mx", "nl",
|
|
|
- "nz", "no", "pe", "pl", "pt", "ro", "ru",
|
|
|
- "sg", "sk", "si", "za", "kr", "es", "sz",
|
|
|
- "se", "ch", "tw", "th", "ua", "gb", "us")
|
|
|
COUNTRY_SOURCES = {
|
|
|
"us": CachedGeoPointSource(RSVPointSource("us"), 10), # cache US specifically since it is commonly used
|
|
|
**{ k: RSVPointSource(k) for k in VALID_COUNTRIES if k not in ("us",) }
|