TfL provides endpoints for data feeds relating to the Santandar Cycles through their Unified API
. The available endpoints are,
/BikePoint
/Place
/Journey
/AccidentStats
You can also download historical journey information
which includes,
- Journey ID
- Bike ID
- Start date
- Start time
- End date
- End time
- Start docking station
- Start docking station ID
- End docking station
- End docking station ID
However, you can't download historical information on the number of available bikes, and docking stations. This information is only available through the Unified API
but provides only the current values.
This library was created to be able to continuously call the TfL /BikePoint
endpoint, and save the NbBikes
, NbDocks
, and NbEmptyDocks
values to a permanent cloud storage (in this case Google Drive).
I will be running this cacher, uploading the data to a dedicated Google Drive account, and making this data available through a link which will shortly be posted on this GitHub repository.
- Install using
setuptools
,
git clone https://github.com/aa-morgan/tfl-bikepoint-cacher.git
cd tfl-bikepoint-cacher
python setup.py install
-
Setup authorisation for Google Drive,
- Go to credentials page
- Click
Create credentials
, choose typeOAuth client ID
and application typeOther
- Under
OAuth 2.0 client IDs
download the credentials file - Rename credentials file to
credentials.json
- Place
credentials.json
in theconfig/
directory
-
Obtain an
api_id
andapi_key
from the (TfL developer site
), and copy them into theconfig/config.txt
configuration file. -
The first time you run this code you will be prompted to grant access to your Google Drive. Once granted, a
token.json
file will appear in theconfig/
directory. This step fails if you run the code through a Jupyter notebook, therefore in order to obtain thetoken.json
file you must run the Python script,
python bikepoint_cacher.py
- You will also be required to enable the
Drive API
. The first time you runbikepoint_cacher.py
an error message will appear containing a URL to enable this API. Wait 1-2 minutes then run the code again and it should work.
Import library,
from bikepointcacher import BikePointCacher, mkdir_GDrive
Define filepath for config.txt
,
config_filepath = '../config/config.txt'
Create remote Google Drive folder,
remote_folder_path = 'TfL_bikepoint_cache'
remote_folder_id = mkdir_GDrive(config_filepath, remote_folder_path)
Instantiate BikePointCacher
object,
cacher = BikePointCacher(config_filepath, remote_folder_id)
Start BikePointCacher
,
cacher.start()
Library | Version |
---|---|
Python |
3.6.1 64bit [GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.57)] |
IPython |
5.3.0 |
OS |
Darwin 17.4.0 x86_64 i386 64bit |
attr |
17.4.0 |
matplotlib |
2.0.2 |
numba |
0.35.0 |
numpy |
1.14.3 |
scipy |
1.00.0 |
sympy |
1.0 |
tqdm |
4.15.0 |
version_information |
1.0.3 |