Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Dashing plugin for Santander Bikes (ex Barclays Bikes) realtime availability

Santander Bikes (ex Barclays Bikes) realtime availability

This widget fetchs the availability of Santander Bikes (ex Barclays Bikes) in realtime using TfL's API.

To install, just type dashing install cfdb32371db7a240263c

Don't forget to add httparty in you Gemfile like this :

    gem 'httparty'

Just update your latitude and longitude in santanderbikes.rb, and include it in your template using the List widget like this :

    <div data-id="bikes" data-view="List" data-unordered="true"
    data-title="Bikes availability" data-moreinfo="Available bikes / Free docks"></div>
require 'httparty'
lat = 51.500987
lon = -0.14178851
radius = 300
SCHEDULER.every '1m' do
puts "bikes"
statuses =
result = HTTParty.get("{lat}&lon=#{lon}&radius=#{radius}&app_id=&app_key=")
raw_info = result.parsed_response["places"]
raw_info.each do |station|
docks_free = nil
docks_bikes = nil
station["additionalProperties"].each do |property|
if property["key"] == "NbBikes"
docks_bikes = property["value"].to_i
elsif property["key"] == "NbEmptyDocks"
docks_free = property["value"].to_i
statuses.push({label: station["commonName"].split(',')[0], value: "#{docks_bikes}/#{docks_free}"})
send_event('bikes', { items: statuses })
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.