pyemtmad.util module

This file contains some utility functions used in the API interface.

class pyemtmad.util.ParkingAdapter(pool_connections=10, pool_maxsize=10, max_retries=0, pool_block=False)

Bases: requests.adapters.HTTPAdapter

Custom HTTP adapter for parking API, as it uses TLSv1.

init_poolmanager(connections, maxsize, block=False)

Initializes a urllib3 PoolManager.

This method should not be called from user code, and is only exposed for use when subclassing the HTTPAdapter.

Parameters:
  • connections – The number of urllib3 connection pools to cache.
  • maxsize – The maximum number of connections to save in the pool.
  • block – Block when no free connections are available.
  • pool_kwargs – Extra keyword arguments used to initialize the Pool Manager.
pyemtmad.util.check_result(data, key='')

Check the result of an API response.

Ideally, this should be done by checking that the value of the resultCode attribute is 0, but there are endpoints that simply do not follow this rule.

Parameters:
  • data (dict) – Response obtained from the API endpoint.
  • key (string) – Key to check for existence in the dict.
Returns:

True if result was correct, False otherwise.

Return type:

bool

pyemtmad.util.date_string(day, month, year)

Build a date string using the provided day, month, year numbers.

Automatically adds a leading zero to day and month if they only have one digit.

Parameters:
  • day (int) – Day number.
  • month (int) – Month number.
  • year (int) – Year number.
Returns:

Date in the format DD/MM/YYYY.

Return type:

str

pyemtmad.util.datetime_string(day, month, year, hour, minute)

Build a date string using the provided day, month, year numbers.

Automatically adds a leading zero to day and month if they only have one digit.

Parameters:
  • day (int) – Day number.
  • month (int) – Month number.
  • year (int) – Year number.
  • hour (int) – Hour of the day in 24h format.
  • minute (int) – Minute of the hour.
Returns:

Date in the format YYYY-MM-DDThh:mm:ss.

Return type:

str

pyemtmad.util.direction_code(direction)

Obtain the integer code of a direction string.

Parameters:direction (str) – forward or backward
Returns:direction code
Return type:int
pyemtmad.util.ints_to_string(ints)

Convert a list of integers to a | separated string.

Parameters:ints (list[int]|int) – List of integer items to convert or single integer to convert.
Returns:Formatted string
Return type:str
pyemtmad.util.language_code(code)

Generate the cultureInfo language code for the API.

Available codes are EN (default) and ES.

Parameters:code (str) – Two-character language code.
Returns:Language code in the format accepted by the API.
Return type:str
pyemtmad.util.response_list(data, key)

Obtain the relevant response data in a list.

If the response does not already contain the result in a list, a new one will be created to ease iteration in the parser methods.

Parameters:
  • data (dict) – API response.
  • key (str) – Attribute of the response that contains the result values.
Returns:

List of response items (usually dict) or None if the key is not present.