datafetcher module

This module provides functionality for retrieving real-time and latest time history level data

datafetcher.dump(data, filename)

Save JSON object to file

Parameters:
  • data (dict) – Json string to be saved
  • filename (str) – Path to file
datafetcher.fetch(url)

Fetch data from url and return fetched JSON object

Parameters:url (str) – url to be fetched
Returns:Json string fetched
Return type:dict
datafetcher.fetch_latest_water_level_data(use_cache=False)

Fetch latest levels from all ‘measures’. Returns JSON object

Parameters:use_cache (bool, optional) – Whether to use cached data
Returns:Json string
Return type:dict
datafetcher.fetch_measure_levels(measure_id, dt)

Fetch measure levels from latest reading and going back a period dt. Return list of dates and a list of values.

Parameters:
  • measure_id (str) – measure_id of the specified station
  • dt (DateTime Object) – Period of time
Returns:

Tuple of lists of the form (dates, levels)

Return type:

tuple

datafetcher.fetch_station_data(use_cache=True)

Fetch data from Environment agency for all active river level monitoring stations via a REST API and return retrieved data as a JSON object.

Fetched data is dumped to a cache file so on subsequent call it can optionally be retrieved from the cache file. This is faster than retrieval over the Internet and avoids excessive calls to the Environment Agency service.

Parameters:use_cache (bool, optional) – Whether to use cached data
Returns:Json string
Return type:dict
datafetcher.load(filename)

Load JSON object from file

Parameters:filename (str) – Path to file
Returns:Json string
Return type:dict