Skip to main content

A Python wrapper for the MobilityLabs Madrid REST API

Project description

Python wrapper for the mobilitylabs API

This repo contains a Python library with some classes to easily access the mobilitylabs API which allows the access to the BusEMTMad, BiciMAD Go and ParkingEMTMad services among others. These services are part of the MobilityLabs Madrid open and interoperable platform.

In addition to the Python wrapper some test applications are included; this will help to let you know how everything works and, on top of that, you can use it to interact with the service once you get your own credencials and store them in the credentials.ini file.

The following are the requirements needed to make it work:

  • Python 3 (3.7.3+)
  • A XClientID and passkey in order to use the services; you can get your own XClientID and passkey by following the steps outlined in Create an application in the EMTing portal, which is reduced down to:
    1. Creating your own developer account
    2. Creating an EMTing Application

This Python library has been successfully tested with OSBDET S21R1 on a Debian 10 x64 host.

Remember to add the library to the PYTHONPATH environment variable if you want to use it from your code or if you want to run the tests Python scripts; you can do so by running the following line within the folder where the repo was cloned:

$ export PYTHONPATH=$PYTHONPATH:`pwd`

If you want to persist this environment variable, add it to your user's profile and it'll be created everytime you log into your computer.

BusEMTMad

The BusEMTMad class allows you to leverage information about buses in the great city of Madrid, which is provided by the EMT (Empresa Municipal de Transportes); this class wrapps the Block 3 TRANSPORT BUSEMTMAD section in the official documentation, although not all the functions/webmethods are wrapped.

The following are the functions/webmethods wrapped at the moment:

  • info_lines(date_ref) - It returns the list of active bus lines in the reference date.
  • info_line(line_id, date_ref) - It returns detailed info of a specific bus line in the reference date.
  • info_stops() - It returns the list of active bus stops and information about them.
  • info_stop(stop_id) - It returns detailed info of a specific bus stop.
  • line_stops(line_id,direction) - It returns the list of bus stops of a bus line keeping in mind the direction (1 - start to end, 2 - end to start)
  • issues(line_id) - It returns details about incidents or issues identified and impacting bus lines.
  • buses_arrivals(stop_id, line_id="") - It returns the real time estimation of how far the buses are from the stop and how much time will take them to get to the bus stop. Only buses from the line specified will be considered (lineId is optional).

test_busemtmad.py let you test this service easily; before you can use it, get your own XClientID and passkey and store them into the credentials.ini file. test_busemtmad.py -h will give you all the details on how to run it:

$ tests/test_busemtmad.py -h
usage: test_busemtmad.py [-h] [-lid LINEID] [-sid STOPID] [-dir {1,2}]
                         {info_lines,info_line,info_stops,info_stop,line_stops,issues,buses_arrivals} credentials_file

positional arguments:
  {info_lines,info_line,info_stops,info_stop,line_stops,issues,buses_arrivals}
                        what is going to be requested to the BusEMTMad service
  credentials_file       path to the file with info to access the service

optional arguments:
  -h, --help            show this help message and exit
  -lid LINEID, --line_id LINEID
                        bus line identifier for actions 'info_line', 'line_stops' and 'issues'; this argument is optional
                        for action 'buses_arrivals'
  -sid STOPID, --stop_id STOPID
                        stop identifier for action 'info_stop' and 'buses_arrivals'
  -dir {1,2}, --direction {1,2}
                        direction to be considered to analyze line info for action 'line_stops'; 1 for start to end, 2
                        for end to start

BiciMAD Go

The BiciMad class allows you to leverage information about bikes and bike stations in the great city of Madrid, which is provided by the BiciMAD GO service; this class wrapps the Block 4 TRANSPORT BICIMAD section in the official documentation, although not all the functions/webmethods are wrapped.

The following are the functions/webmethods wrapped at the moment:

  • info_bike_stations() - It returns the details of Madrid BiciMad Stations.
  • info_bike_station(bike_station_id) - It returns the details of a specific Madrid BiciMad Station.
  • info_bikes() - It returns the details of Madrid BiciMad bikes.
  • info_bike(bike_id): - It returns the details of a specific bike from the Madrid BiciMad service.

test_bicimad.py let you test this service easily; before you can use it, get your own XClientID and passkey and store them into the credentials.ini file. test_bicimad.py -h will give you all the details on how to run it:

$ tests/test_bicimad.py -h
usage: test_bicimad.py [-h] [-sid BIKESTATIONID] [-bid BIKEID]
                       {info_bike_stations,info_bike_station,info_bikes,info_bike} credentials_file

positional arguments:
  {info_bike_stations,info_bike_station,info_bikes,info_bike}
                        what is going to be requested to the BiciMAD GO service
  credentialsFile       path to the file with info to access the service

optional arguments:
  -h, --help            show this help message and exit
  -sid BIKESTATIONID, --bike_station_id BIKESTATIONID
                        bike station identifier for action 'info_bike_station'
  -bid BIKEID, --bike_id BIKEID
                        bike identifier for action 'info_bike'

ParkingEMTMad

The ParkingEMTMad class allows you to leverage information about parking areas in the great city of Madrid, which is provided by the EMT (Empresa Municipal de Transportes); this class wrapps the Block 5 PARKINGS section in the official documentation, although not all the functions/webmethods are wrapped.

The following are the functions/webmethods wrapped at the moment:

  • info_parkings() - It returns the list of active parking areas operated by the EMT.
  • info_parking(parking_id) - It returns the details of a specific parking area.
  • availability() - It returns availability for those parking areas publishing this information. Not all of them make this information public.

test_parkings.py let you test this service easily; before you can use it, get your own XClientID and passkey and store them into the credentials.ini file. test_parkings.py -h will give you all the details on how to run it:

$ tests/test_parkings.py -h
usage: test_parkings.py [-h] [-id PARKINGID] {info_parkings,info_parking,availability} credentials_file

positional arguments:
  {info_parkings,info_parking,availability}
                        what is going to be requested to the ParkingEMTMad service
  credentialsFile       path to the file with info to access the service

optional arguments:
  -h, --help            show this help message and exit
  -id PARKINGID, --parking_id PARKINGID
                        parking area identifier for action 'info_parking'

Changelog

  • v0.1 (20210410) - initial release.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mobilitylabs-bsdprof-0.1.3.tar.gz (30.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mobilitylabs_bsdprof-0.1.3-py3-none-any.whl (32.2 kB view details)

Uploaded Python 3

File details

Details for the file mobilitylabs-bsdprof-0.1.3.tar.gz.

File metadata

  • Download URL: mobilitylabs-bsdprof-0.1.3.tar.gz
  • Upload date:
  • Size: 30.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.7.0 requests/2.21.0 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.7.3

File hashes

Hashes for mobilitylabs-bsdprof-0.1.3.tar.gz
Algorithm Hash digest
SHA256 96ab84fc534e30e5f8850f67572d69fcbd302245200eef3abc6faf9ddb862df5
MD5 c2ae70f6cbdc77aff58ce7621f4e8477
BLAKE2b-256 1b21a43ba3e6b9e9ab24cae4475de15011179834c070d44ac9043c370cf9ecea

See more details on using hashes here.

File details

Details for the file mobilitylabs_bsdprof-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: mobilitylabs_bsdprof-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 32.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.7.0 requests/2.21.0 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.7.3

File hashes

Hashes for mobilitylabs_bsdprof-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 5638fe638c3630d7967eab4ea6f6033e7f157fe36e795ea59e7612fe178c08ec
MD5 11a3921688db8ec2390e6b401c363e2f
BLAKE2b-256 6f2c32958ac32fe2674b922be3c224d9c976ef0ad3eb8bce3f916f00f6fecbca

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page