aboutsummaryrefslogtreecommitdiff
path: root/data/script.py
blob: e7e37e117a57ddc6497563e2486896f8cb70ed3b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
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))