Code Monkey home page Code Monkey logo

ecobici_py's Introduction

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.

ecobici_py's People

Contributors

sainoba avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.