davegimo

Untitled

Mar 30th, 2021
43
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. def create_delta_list_hero(file, city, province):
  2.  
  3. with open(file) as json_file:
  4. json_data = json.load(json_file)
  5.  
  6. lista = []
  7. link = "https://geocode.search.hereapi.com/v1/geocode?q="
  8. key = "&apiKey=ZNdP6ytzdqUuIaTudctEdR4Zv-L0_s8mhJoI6k1AF1s"
  9.  
  10. for p in json_data['features']:
  11. s = pref_via(p['pref_via'])
  12. if s == "":
  13. continue
  14. else:
  15. via = s + "+" + p['nome_via'] + "+" + str(p['num_civico']) + "+" + city + "+" + province
  16. uri = link + via + key
  17. x = requests.get(uri)
  18. data = x.json()
  19.  
  20. wgs84 = parse_tuple(p['coord_wgs84'])
  21. lat = wgs84[1]
  22. lng = wgs84[0]
  23.  
  24. if data["items"] == []:
  25. continue
  26. print("warning")
  27.  
  28. #print(data["items"][0]["scoring"]["queryScore"])
  29.  
  30. if data["items"][0]["scoring"]["queryScore"] > 0.98:
  31. print(data["items"][0]["scoring"]["queryScore"])
  32. delta_x = data["items"][0]["position"]["lng"] - lng
  33. delta_y = data["items"][0]["position"]["lat"] - lat
  34. lista.append([delta_x, delta_y])
  35.  
  36.  
  37.  
  38. #print(delta_x, delta_y)
  39.  
  40. return lista
RAW Paste Data