123456789101112131415161718192021222324252627282930313233343536 |
- import requests
- from .shared import point_has_streetview, PointSource
- rsv_url = "https://randomstreetview.com/data"
- def call_random_street_view(only_america=False):
- """
- Returns an array of (some number of) tuples, each being (latitude, longitude).
- All points will be valid streetview coordinates. There is no guarantee as to the
- length of this array (it may be empty), but it will never be None.
- This function calls the streetview metadata endpoint - there is no quota consumed.
- """
- rsv_js = requests.post(rsv_url, data={"country": "us" if only_america else "all"}).json()
- if not rsv_js["success"]:
- return []
-
- return [
- (point["lat"], point["lng"])
- for point in rsv_js["locations"]
- if point_has_streetview(point["lat"], point["lng"])
- ]
- class RSVPointSource(PointSource):
- def __init__(self, stock_target=20, only_america=False):
- super().__init__(stock_target=stock_target)
- self.only_america = only_america
-
- def _restock_impl(self, n):
- points = []
- while len(points) < n:
- points.extend(call_random_street_view(only_america=self.only_america))
- return points
|