lib.py 1.1 KB

123456789101112131415161718192021222324252627282930313233343536
  1. import json
  2. import requests
  3. from flask import current_app
  4. metadata_url = "https://maps.googleapis.com/maps/api/streetview/metadata"
  5. mapcrunch_url = "http://www.mapcrunch.com/_r/"
  6. def generate_coord(key):
  7. """
  8. Takes in a Google API key.
  9. Returns (latitude, longitude) of usable coord (where google has data).
  10. Returns None if, after trying several random points, no usable coords could be found.
  11. This function calls the streetview metadata endpoint - there is no quota consumed
  12. """
  13. points_res = requests.get(mapcrunch_url).text
  14. points_js = json.loads(points_res.strip("while(1); "))
  15. for lat, lng in points_js["points"]:
  16. params = {
  17. "key": key
  18. "location": f"{lat},{lng}"
  19. }
  20. js = requests.get(metadata_url, params=params).json()
  21. if js["status"] != "ZERO_RESULTS":
  22. return (lat, lng)
  23. def score(target, guess):
  24. """
  25. Takes in two (latitude, longitude) pairs and produces an int score.
  26. Score is in the (inclusive) range [0, 5000]
  27. Higher scores are closer.
  28. """
  29. pass