Created
November 24, 2019 16:33
-
-
Save theSekyi/83344479520ea330b3ac85a43d2be04d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas as pd | |
import csv | |
import openrouteservice | |
from openrouteservice.directions import directions | |
import uuid | |
import time | |
em = "#" | |
m1 = "#" | |
m2 = "#" | |
client = openrouteservice.Client( | |
key=m1 | |
) # Specify your personal API key | |
def create_csv(rt,name): | |
keys = rt[0].keys() | |
with open(f'{name}.csv', 'w') as output_file: | |
dict_writer = csv.DictWriter(output_file, keys) | |
dict_writer.writeheader() | |
dict_writer.writerows(rt) | |
def unique_map(df): | |
al = [] | |
for i in df.index: | |
coords = ( | |
(df.at[i, "PickupLong"], df.at[i, "PickupLat"]), | |
(df.at[i, "DestinationLong"], df.at[i, "DestinationLat"]), | |
) | |
al.append(coords) | |
al_unique = tuple(set(al)) | |
return al_unique | |
def get_details(al_unique): | |
rt = [] | |
name = uuid.uuid1() | |
for cord in al_unique: | |
rt.append(directions(client, cord)) | |
time.sleep(1.5) | |
print(f"{cord} appended") | |
print("CSV creation beginning") | |
create_csv(rt,name) | |
print("CSV creation done") | |
return rt | |
df = pd.read_csv("df_map.csv") | |
al_unique = unique_map(df) | |
m1 = al_unique[0:2000] | |
# m2 = al_unique[4000:8000] | |
# m3 = al_unique[8000:12000] | |
# m4 = al_unique[12000:16000] | |
# m5 = al_unique[16000:] | |
#m1_lst = get_details(m1) | |
# m2_lst = get_details(m2) | |
# m3_lst = get_details(m3) | |
# m4_lst = get_details(m4) | |
# m5_lst = get_details(m5) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment