Advertisement
miszczo

Untitled

Apr 20th, 2023
646
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.56 KB | None | 0 0
  1.     if start_loc not in locates_dict.keys():
  2.         print(colored("Adding new key from row: ","green")+ str(row))
  3.         print(colored("Location:","green")+colored(start_loc,"blue"))
  4.         url = "https://www.google.pl/maps/place/" + start_loc.replace("/","%2F")
  5.         print(colored(url,"blue"))
  6.         url = url.replace("+","%2B")
  7.         url = url.replace(",","")
  8.  
  9.         print(colored(url,"blue"))
  10.  
  11.         r = requests.get(url, headers=headers, cookies=cookies)
  12.         result = re.search('@(-?\d+\.\d+),(-?\d+\.\d+),', str(r.content))
  13.         try:
  14.             coord = result.group(1) + "," + result.group(2)
  15.         except:
  16.             print(colored("Cannot get coordinates line: ","red"),colored(str(row)))
  17.             locates_dict[start_loc] = "TODO"
  18.             continue
  19.        
  20.         print(colored("location: " + result.group(1) +
  21.               "," + result.group(2) + " [lat,lon]","magenta"))
  22.         # get location from openstreetmaps
  23.         address = result.group(1) + "," + result.group(2)
  24.         location = geolocator.geocode(address, addressdetails=True)
  25.         print(colored(location.address,"magenta"))
  26.         locates_dict[start_loc] = location.address
  27.         #locates_dict = dict(sorted(locates_dict.items()))
  28.         with open("locates_dict.json", "w",encoding='utf8') as fp:
  29.             json.dump(locates_dict, fp,ensure_ascii=False)  # encode dict into JSON
  30.     else :
  31.          print(colored("Key exist: ","green") + colored(str(row) ,"green") +" "+ colored(start_loc, "yellow") +" - " + colored(locates_dict[start_loc],"blue"))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement