Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pandas as pd
- import requests
- def generate_json(points):
- f = open('d.json', 'w+')
- start = '{\"type\": \"FeatureCollection\",\"features\": ['
- f.write(start)
- i = 0
- for p in points:
- body = '{\"type\": \"Feature\", \"id\": ' + str(i) + ', \"geometry\": {\"type\": \"Point\", \"coordinates\": [' + p[0] + ', ' + p[1] + ']}, \"properties\": {\"clusterCaption\": \"<strong><s>Еще</s> одна</strong> метка\"}},'
- i += 1
- f.write(body)
- end = ']}'
- f.write(end)
- def main():
- data = pd.read_csv('alfa.csv', ';')
- data = data[10:20]
- print(len(data))
- points = []
- for index, row in data.iterrows():
- geocode = row['Город'] + ', ' + row['Адрес доставки']
- print(geocode)
- r = requests.get('https://geocode-maps.yandex.ru/1.x/?format=json&geocode=' + geocode).json()
- x = r['response']['GeoObjectCollection']['featureMember'][0]['GeoObject']['Point']['pos']
- lon, lat = x.split(' ')
- points.append((lat, lon))
- print(lat, lon)
- generate_json(points)
- if __name__ == '__main__':
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement