shared.py 1.0 KB

123456789101112131415161718192021222324252627282930313233343536
  1. from typing import List, Tuple, Union, Dict
  2. import collections
  3. import logging
  4. import aiohttp
  5. from ..schemas import GenMethodEnum, CountryCode
  6. # Google API key, with access to Street View Static API
  7. # this can be safely committed due to permission restriction
  8. google_api_key = "AIzaSyAqjCYR6Szph0X0H_iD6O1HenFhL9jySOo"
  9. metadata_url = "https://maps.googleapis.com/maps/api/streetview/metadata"
  10. logger = logging.getLogger(__name__)
  11. aiohttp_client = aiohttp.ClientSession()
  12. async def point_has_streetview(lat, lng):
  13. """
  14. Returns True if the streetview metadata endpoint says a given point has
  15. data available, and False otherwise.
  16. This function calls the streetview metadata endpoint - there is no quota consumed.
  17. """
  18. params = {
  19. "key": google_api_key,
  20. "location": f"{lat},{lng}",
  21. }
  22. async with aiohttp_client.get(metadata_url, params=params) as response:
  23. body = await response.json()
  24. return body["status"] == "OK"
  25. class ExhaustedSourceError(Exception):
  26. pass