#!/usr/bin/env python3 import requests import re import json res = requests.get('https://api.krispykreme.com/shops/?latitude=44.7601&longitude=-93.2748&count=1000&shopFeatureFlags=0&includeGroceryStores=false&includeShops=true') locations = json.loads(res.text) stores = [] for location in locations: stores.append({ "type": "Feature", "geometry": { "type": "Point", "coordinates": [float(location['longitude']), float(location['latitude'])], # yes, [lon, lat] since it's [x, y] }, "properties": { 'address': location['address1'].title(), 'city': location['city'].title(), 'state': location['state'], 'zip': location['zipCode'], 'website': location['pagesUrl'], }, }) geojson = { "type": "FeatureCollection", "features": stores, } with open("data.geojson", "w") as f: f.write(json.dumps(geojson)) print(f"{len(locations)} locations found")