Skip to content

Commit 792f78b

Browse files
committed
Add local places script to retrieve nearby information
1 parent 129539c commit 792f78b

File tree

3 files changed

+52
-0
lines changed

3 files changed

+52
-0
lines changed

README.md

+4
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,7 @@ Unfortunately both data sets are not under the Open Government Licence and needs
3030
[Commercial and Corporate Owners](https://www.gov.uk/guidance/hm-land-registry-commercial-and-corporate-ownership-data)
3131

3232
[Overseas Companies Ownership Data](https://www.gov.uk/government/publications/overseas-companies-ownership-data-technical-specification/overseas-companies-ownership-data-technical-specification)
33+
34+
### [Local Places Data](local-places)
35+
36+
This an integration with Google Places API to retrieve local information for given lat/long within a radius. This is a starting point on creating a more detailed area map of a location and best used with Postcode geo lat/long.

local-places/README.md

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Local Places Data
2+
3+
This is Google Places integration for finding local information for any given location.
4+
The data is retrieved using a script and the output is in a JSON format, suitable for saving to a file.
5+
6+
## What tools are available
7+
1. The `get-local-places` is a command line tool that retrieves local places data for a given point.
8+
9+
## Notes on Schema
10+
No schema is provided here as you may not necessarily want to store them permanently and retrieve these details on a real time basis only. If you do want to store them, then it is recommended to use a short to long term caching strategy so your data is not too stale.
11+
12+
## How to run the downloader
13+
14+
The `get-local-places.py` script requires a Google API key which you can get from their account dashboard.
15+
Once you have the key you can either provide it as a parameter to the script or set is an environment variable called `GOOGLE_API_KEY`.
16+
17+
The general format for running this script is:
18+
19+
```get-local-places.py <lat> <long> [-p PAGE] [-k KEY]```
20+
21+
The provided key will override the environment variable and the page parameter is for retrieving the next page
22+
of results for the same query. If there are multiple pages the output will provide a next page token which you can pass in here.

local-places/get-local-places.py

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/usr/bin/env python3
2+
3+
import argparse
4+
import json
5+
import os
6+
from urllib import request
7+
8+
API_URL = 'https://maps.googleapis.com/maps/api/place/textsearch/json?key={key}&query={query}&location={loc}&radius={radius}'
9+
10+
parser = argparse.ArgumentParser()
11+
parser.add_argument('lat', help='Latitude')
12+
parser.add_argument('lng', help='Longitude')
13+
parser.add_argument('-k', '--key', help='The Google API key, will override any GOOGLE_API_KEY env variable')
14+
parser.add_argument('-p', '--page', help='The next page token if available')
15+
args = parser.parse_args()
16+
17+
api_key = args.key or os.environ['GOOGLE_API_KEY']
18+
19+
req_url = API_URL.format(key=api_key, query='shop', loc=args.lat+','+args.lng, radius='500')
20+
21+
if (args.page):
22+
req_url = req_url+'&pagetoken='+args.page
23+
24+
with request.urlopen(req_url) as resp:
25+
json_resp = json.loads(resp.read())
26+
print(json.dumps(json_resp, indent=2))

0 commit comments

Comments
 (0)