Skip to content

Latest commit

 

History

History
155 lines (122 loc) · 3.93 KB

README.md

File metadata and controls

155 lines (122 loc) · 3.93 KB

Ecobici python wrapper

Build Status PyPI version GitHub

Ecobici logo

Installation

pip install ecobici

Usage

# Import module
from ecobici import Ecobici

# Initialize client
client = Ecobici(your_client_id, your_client_secret)

# Get dictionary containing stations
stations = client.get_stations()

# Get dictionary containing the status of stations
stations_status = client.get_stations_status()

# (Optional) Force refresh token
client.refresh_token()

Examples

Get the name of the first station

from ecobici import Ecobici
client = Ecobici(your_client_id, your_client_secret)
list_of_stations = client.get_stations()["stations"]

print("The name of the first station is ", list_of_stations[0]["name"])

Check the Data structure section for more information

Get the status of the third station

from ecobici import Ecobici
client = Ecobici(your_client_id, your_client_secret)
list_of_stations = client.get_stations_status()["stationsStatus"]

print("The status of the third station is ", list_of_stations[3]["status"])

Check the Data structure section for more information

Data structure

Stations structure

This module translate the json objects to python objects and returns it to the user, it doesn't unwraps it because I didn't want to modify the data.

The econduce's API returns data in the following json format, that's why you have to manually unwrap it with client.get_stations_status()["stations"]:

{
    "stations": [
        {
            "id": 448,
            "name": "448 DR. ANDRADE - ARCOS DE BELÉN",
            "address": "DR. ANDRADE ARCOS DE BELÉN",
            "addressNumber": "S/N",
            "zipCode": null,
            "districtCode": null,
            "districtName": null,
            "altitude": null,
            "nearbyStations": [
                448
            ],
            "location": {
                "lat": 19.426611,
                "lon": -99.14447
            },
            "stationType": "BIKE,TPV"
        },
    ]
}

Structure and types

Key Type
id int
name str
address str
addressNumber str
zipCode str
districtCode str
districtName str
nearbyStations list with id (int)
location list
stationType str

Location list:

Key Type
lat float
lon float

Latitud and logitud are coordinates based on the World Geodetic System (WGS84).

Status structure

This module translate the json objects to python objects and returns it to the user, it doesn't unwraps it because I didn't want to modify the data.

The econduce's API returns data in the following json format, that's why you have to manually unwrap it with client.get_stations_status()["stationsStatus"]:

{
    "stationsStatus": [
        {
            "id": 1,
            "status": "OPN",
            "availability": {
                "bikes": 4,
                "slots": 23
            }
        },
    ]
}      

Structure and types

Key Type
id int
status str (OPN means open, CLS means closed)
availability list

Availability list:

Key Type
bikes int
slots int

Test

python3 -m pytest ecobici/test.py

Notes

  • There's no need to refresh the token when it expires. The client does it automatically.
  • Ecobici's API can return null values. It's up to you to verify that the value you want to access is defined.
  • You can find more information about the API structure here: Spanish documentation.