Advertisement
Guest User

Untitled

a guest
Apr 24th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.14 KB | None | 0 0
  1. import pandas as pd
  2. import requests
  3.  
  4.  
  5. def generate_json(points):
  6.     f = open('d.json', 'w+')
  7.     start = '{\"type\": \"FeatureCollection\",\"features\": ['
  8.     f.write(start)
  9.  
  10.     i = 0
  11.     for p in points:
  12.         body = '{\"type\": \"Feature\", \"id\": ' + str(i) + ', \"geometry\": {\"type\": \"Point\", \"coordinates\": [' + p[0] + ', ' + p[1] + ']}, \"properties\": {\"clusterCaption\": \"<strong><s>Еще</s> одна</strong> метка\"}},'
  13.         i += 1
  14.         f.write(body)
  15.  
  16.     end = ']}'
  17.     f.write(end)
  18.  
  19.  
  20. def main():
  21.     data = pd.read_csv('alfa.csv', ';')
  22.     data = data[10:20]
  23.     print(len(data))
  24.     points = []
  25.  
  26.     for index, row in data.iterrows():
  27.         geocode = row['Город'] + ', ' + row['Адрес доставки']
  28.         print(geocode)
  29.         r = requests.get('https://geocode-maps.yandex.ru/1.x/?format=json&geocode=' + geocode).json()
  30.         x = r['response']['GeoObjectCollection']['featureMember'][0]['GeoObject']['Point']['pos']
  31.         lon, lat = x.split(' ')
  32.         points.append((lat, lon))
  33.         print(lat, lon)
  34.     generate_json(points)
  35.  
  36.  
  37. if __name__ == '__main__':
  38.     main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement