diff options
Diffstat (limited to 'data/script.py')
-rw-r--r-- | data/script.py | 90 |
1 files changed, 90 insertions, 0 deletions
diff --git a/data/script.py b/data/script.py new file mode 100644 index 0000000..138435f --- /dev/null +++ b/data/script.py @@ -0,0 +1,90 @@ +api_key="499c19189bmsh1de144300936427p134bd5jsnbdcec35e8f65" + +import urllib.parse +import requests +import json + +boroughs = [ + "barking and dagenham", + "barnet", + "bexley", + "brent", + "bromley", + "camden", + "croydon", + "ealing", + "enfield", + "greenwich", + "hackney", + "hammersmith and fulham", + "haringey", + "harrow", + "havering", + "hillingdon", + "hounslow", + "islington", + "kensington and chelsea", + "kingston upon thames", + "lambeth", + "lewisham", + "merton", + "newham", + "redbridge", + "richmond upon thames", + "southwark", + "sutton", + "tower hamlets", + "waltham forest", + "wandsworth", + "westminster"] + +base_url = "https://wyre-data.p.rapidapi.com/restaurants/localauthority/" + +final = [] + +for borough in boroughs: + borough_encoded = urllib.parse.quote(borough) + response = requests.get(base_url + borough_encoded, headers={"x-rapidapi-key": api_key}) + results = response.json() + + for result in results: + bizType = result.get("BusinessType", "missing") + if(bizType == "Pub/bar/nightclub"): + new_obj = { + "objectID": result["_id"], + "name": result.get("BusinessName", ""), + "business_type": result.get("BusinessType"), + "borough": result.get("LocalAuthorityName", ""), + "postcode": result.get("PostCode", ""), + "address": ", ".join(filter(None, [result.get("AddressLine1", ""), result.get("AddressLine2", "")])), + "_geoloc": { + "lat": result.get("Geocode_Latitude") or 0.0, + "lng": result.get("Geocode_Longitude") or 0.0, + } + } + final.append(new_obj) + + + +with open("./data/pubs.json", "w") as f: + f.write(json.dumps(final)) + +# with open("./data/pubs.json", "r") as f: +# hello = json.load(f) +# print(hello[0]) + + +# from algoliasearch.search_client import SearchClient + +# client = SearchClient.create('YSWWVAX5RB', '31ce537df5b4594e34a03673e09cd662') +# index = client.init_index('pubfinder') + +# with open("./data/pubs.json", "r+") as f: +# records = json.load(f) +# for record in records: +# if record.get("geoloc", {}).get("lat", None) is None: +# records.remove(record) +# f.write(json.dumps(records)) + + + |