def test_network_by_uid(self): responses.add(responses.GET, 'https://api.citybik.es/v2/networks/foo', json=mockresponses.network) client = citybikes.Client() foo = citybikes.Network(client, uid='foo') assert foo.data == mockresponses.network['network']
def test_network_json(self): responses.add(responses.GET, 'https://api.citybik.es/v2/networks/foo', json=mockresponses.network) client = citybikes.Client() network = citybikes.Network(client, uid='foo') assert json.dumps(network, cls=citybikes.resource.JSONEncoder)
def test_stations(self): responses.add(responses.GET, 'https://api.citybik.es/v2/networks/foo', json=mockresponses.network) client = citybikes.Client() foo = citybikes.Network(client, uid='foo') stations = list(foo.stations) for s in stations: assert isinstance(s, citybikes.Station)
def test_near_stations(self): responses.add(responses.GET, 'https://api.citybik.es/v2/networks/foo', json=mockresponses.network) client = citybikes.Client() network = citybikes.Network(client, uid='foo') battery = [ (network.stations.near(0.0, 0.0), [1, 2, 3]), (network.stations.near(25.0, 25.0), [2, 3, 1]), (network.stations.near(100.0, 100.0), [3, 2, 1]), ] for nets, expected in battery: assert [n['id'] for n, dist in nets] == expected
# import citybikes import paho.mqtt.publish as publish import paho.mqtt.client as mqtt import simplejson as json from datetime import datetime mqtt_host = "localhost" MQTT_AUTH = {'username': '******', 'password': '******'} # Check City Bikes API docs networkuid = 'ford-gobike' client = citybikes.Client() network = citybikes.Network(client, uid=networkuid) network = network['stations'] myStations = ["8302e5d11a6c84bac27a774de41474f9", \ "c2648d0ffed4d1f710ccaf79e9a304fa", \ "3f5c0437929a0f6dbc32f116850a4196", \ "36aa8ab83177d5f5beb83685c7f645d3"] for station in network: for id in myStations: if id == station['id']: percentFull = int(((station['free_bikes'] / float( (station['free_bikes'] + station['empty_slots']))) * 100)) topic = "CityBikes/" + station['name'] payload = json.dumps({ 'free_bikes':station['free_bikes'], \ 'empty_slots':station['empty_slots'], \