pyowm.stationsapi30 package

Subpackages

Submodules

pyowm.stationsapi30.buffer module

class pyowm.stationsapi30.buffer.Buffer(station_id)[source]

Bases: object

append(measurement)[source]

Appends the specified Measurement object to the buffer :param measurement: a measurement.Measurement instance

append_from_dict(the_dict)[source]

Creates a measurement.Measurement object from the supplied dict and then appends it to the buffer :param the_dict: dict

append_from_json(json_string)[source]

Creates a measurement.Measurement object from the supplied JSON string and then appends it to the buffer :param json_string: the JSON formatted string

created_at = None
creation_time(timeformat='unix')[source]

Returns the UTC time of creation of this aggregated measurement

Parameters:

timeformat (str) – the format for the time value. May be: ‘unix’ (default) for UNIX time, ‘iso’ for ISO8601-formatted string in the format YYYY-MM-DD HH:MM:SS+00 or date for a datetime.datetime object

Returns:

an int or a str or a datetime.datetime object or None

Raises:

ValueError

empty()[source]

Drops all measurements of this buffer instance

measurements = None
sort_chronologically()[source]

Sorts the measurements of this buffer in chronological order

sort_reverse_chronologically()[source]

Sorts the measurements of this buffer in reverse chronological order

station_id = None

pyowm.stationsapi30.measurement module

class pyowm.stationsapi30.measurement.AggregatedMeasurement(station_id, timestamp, aggregated_on, temp=None, humidity=None, wind=None, pressure=None, precipitation=None)[source]

Bases: object

A class representing an aggregation of measurements done by the Stations API on a specific time-frame. Values for the aggregation time-frame can be: ‘m’ (minute), ‘h’ (hour) or ‘d’ (day)

Parameters:
  • station_id (str) – unique station identifier

  • timestamp (int) – reference UNIX timestamp for this measurement

  • aggregated_on (string between 'm','h' and 'd') – aggregation time-frame for this measurement

  • temp (dict or None) – optional dict containing temperature data

  • humidity (dict or None) – optional dict containing humidity data

  • wind (dict or None) – optional dict containing wind data

  • pressure (dict or None) – optional dict containing pressure data

  • precipitation (dict or None) – optional dict containing precipitation data

ALLOWED_AGGREGATION_TIME_FRAMES = ['m', 'h', 'd']
creation_time(timeformat='unix')[source]

Returns the UTC time of creation of this aggregated measurement

Parameters:

timeformat (str) – the format for the time value. May be: ‘unix’ (default) for UNIX time, ‘iso’ for ISO8601-formatted string in the format YYYY-MM-DD HH:MM:SS+00 or date for a datetime.datetime object

Returns:

an int or a str or a datetime.datetime object or None

Raises:

ValueError

classmethod from_dict(the_dict)[source]

Parses an AggregatedMeasurement instance out of a data dictionary. Only certain properties of the data dictionary are used: if these properties are not found or cannot be parsed, an exception is issued.

Parameters:

the_dict (dict) – the input dictionary

Returns:

an AggregatedMeasurement instance or None if no data is available

Raises:

ParseAPIResponseError if it is impossible to find or parse the data needed to build the result

to_dict()[source]

Dumps object fields into a dict

Returns:

a dict

class pyowm.stationsapi30.measurement.Measurement(station_id, timestamp, temperature=None, wind_speed=None, wind_gust=None, wind_deg=None, pressure=None, humidity=None, rain_1h=None, rain_6h=None, rain_24h=None, snow_1h=None, snow_6h=None, snow_24h=None, dew_point=None, humidex=None, heat_index=None, visibility_distance=None, visibility_prefix=None, clouds_distance=None, clouds_condition=None, clouds_cumulus=None, weather_precipitation=None, weather_descriptor=None, weather_intensity=None, weather_proximity=None, weather_obscuration=None, weather_other=None)[source]

Bases: object

creation_time(timeformat='unix')[source]

Returns the UTC time of creation of this raw measurement

Parameters:

timeformat (str) – the format for the time value. May be: ‘unix’ (default) for UNIX time, ‘iso’ for ISO8601-formatted string in the format YYYY-MM-DD HH:MM:SS+00 or date for a datetime.datetime object

Returns:

an int or a str or a datetime.datetime object or None

Raises:

ValueError

classmethod from_dict(the_dict)[source]
to_JSON()[source]

Dumps object fields into a JSON formatted string

Returns:

the JSON string

to_dict()[source]

Dumps object fields into a dictionary

Returns:

a dict

pyowm.stationsapi30.persistence_backend module

class pyowm.stationsapi30.persistence_backend.JSONPersistenceBackend(json_file_path, station_id)[source]

Bases: PersistenceBackend

A PersistenceBackend loading/saving data to a JSON file. Data will be saved as a JSON list, each element being representing data of a pyowm.stationsapi30.measurement.Measurement object.

Parameters:
  • json_file_path (str) – path to the JSON file

  • station_id (str) – unique OWM-provided ID of the station whose data is read/saved

load_to_buffer()[source]

Reads meteostation measurement data into a pyowm.stationsapi30.buffer.Buffer object.

Returns:

a pyowm.stationsapi30.buffer.Buffer instance

persist_buffer(buffer)[source]

Saves data contained into a pyowm.stationsapi30.buffer.Buffer object in a durable form.

Parameters:

buffer (pyowm.stationsapi30.buffer.Buffer instance) – the Buffer object to be persisted

class pyowm.stationsapi30.persistence_backend.PersistenceBackend[source]

Bases: object

A global abstract class representing an I/O manager for buffer objects containing raw measurements.

abstractmethod load_to_buffer()[source]

Reads meteostation measurement data into a pyowm.stationsapi30.buffer.Buffer object.

Returns:

a pyowm.stationsapi30.buffer.Buffer instance

abstractmethod persist_buffer(buffer)[source]

Saves data contained into a pyowm.stationsapi30.buffer.Buffer object in a durable form.

Parameters:

buffer (pyowm.stationsapi30.buffer.Buffer instance) – the Buffer object to be persisted

pyowm.stationsapi30.station module

class pyowm.stationsapi30.station.Station(id, created_at, updated_at, external_id, name, lon, lat, alt, rank)[source]

Bases: object

A class representing a meteostation in Stations API. A reference about OWM stations can be found at: http://openweathermap.org/stations

Parameters:
  • id (str) – unique OWM identifier for the station

  • created_at (str in format %Y-%m-%dT%H:%M:%S.%fZ) – UTC timestamp marking the station registration.

  • updated_at (str in format %Y-%m-%dT%H:%M:%S.%fZ) – UTC timestamp marking the last update to this station

  • external_id (str) – user-given identifier for the station

  • name (str) – user-given name for the station

  • lon (float) – longitude of the station

  • lat (float) – latitude of the station

  • alt (float) – altitude of the station

  • rank (int) – station rank

creation_time(timeformat='unix')[source]

Returns the UTC time of creation of this station

Parameters:

timeformat (str) – the format for the time value. May be: ‘unix’ (default) for UNIX time, ‘iso’ for ISO8601-formatted string in the format YYYY-MM-DD HH:MM:SS+00 or date for a datetime.datetime object

Returns:

an int or a str or a datetime.datetime object or None

Raises:

ValueError

classmethod from_dict(the_dict)[source]

Parses a Station instance out of a data dictionary. Only certain properties of the data dictionary are used: if these properties are not found or cannot be parsed, an exception is issued.

Parameters:

the_dict (dict) – the input dictionary

Returns:

a Station instance or None if no data is available

Raises:

ParseAPIResponseError if it is impossible to find or parse the data needed to build the result

last_update_time(timeformat='unix')[source]

Returns the UTC time of the last update on this station’s metadata

Parameters:

timeformat (str) – the format for the time value. May be: ‘unix’ (default) for UNIX time, ‘iso’ for ISO8601-formatted string in the format YYYY-MM-DD HH:MM:SS+00 or date for a datetime.datetime object

Returns:

an int or a str or a datetime.datetime object or None

Raises:

ValueError

to_dict()[source]

Dumps object to a dictionary

Returns:

a dict

pyowm.stationsapi30.stations_manager module

class pyowm.stationsapi30.stations_manager.StationsManager(API_key, config)[source]

Bases: object

A manager objects that provides a full interface to OWM Stations API. Mainly it implements CRUD methods on Station entities and the corresponding measured datapoints.

Parameters:
  • API_key (str) – the OWM Weather API key

  • config (dict) – the configuration dictionary

Returns:

a StationsManager instance

Raises:

AssertionError when no API Key is provided

create_station(external_id, name, lat, lon, alt=None)[source]

Create a new station on the Station API with the given parameters

Parameters:
  • external_id (str) – the user-given ID of the station

  • name (str) – the name of the station

  • lat (float) – latitude of the station

  • lon (float) – longitude of the station

  • alt (float) – altitude of the station

Returns:

the new pyowm.stationsapi30.station.Station object

delete_station(station)[source]

Deletes the Station API record identified by the ID of the provided pyowm.stationsapi30.station.Station, along with all its related measurements

Parameters:

station (pyowm.stationsapi30.station.Station) – the pyowm.stationsapi30.station.Station object to be deleted

Returns:

None if deletion is successful, an exception otherwise

get_measurements(station_id, aggregated_on, from_timestamp, to_timestamp, limit=100)[source]

Reads measurements of a specified station recorded in the specified time window and aggregated on minute, hour or day. Optionally, the number of resulting measurements can be limited.

Parameters:
  • station_id (str) – unique station identifier

  • aggregated_on (string between 'm','h' and 'd') – aggregation time-frame for this measurement

  • from_timestamp (int) – Unix timestamp corresponding to the beginning of the time window

  • to_timestamp (int) – Unix timestamp corresponding to the end of the time window

  • limit (int) – max number of items to be returned. Defaults to 100

Returns:

list of pyowm.stationsapi30.measurement.AggregatedMeasurement objects

get_station(id)[source]

Retrieves a named station registered on the Stations API.

Parameters:

id (str) – the ID of the station

Returns:

a pyowm.stationsapi30.station.Station object

get_stations()[source]

Retrieves all of the user’s stations registered on the Stations API.

Returns:

list of pyowm.stationsapi30.station.Station objects

send_buffer(buffer)[source]

Posts to the Stations API data about the Measurement objects contained into the provided Buffer instance.

Parameters:

buffer (pyowm.stationsapi30.buffer.Buffer instance) – the pyowm.stationsapi30.buffer.Buffer instance whose measurements are to be posted

Returns:

None if creation is successful, an exception otherwise

send_measurement(measurement)[source]

Posts the provided Measurement object’s data to the Station API.

Parameters:

measurement (pyowm.stationsapi30.measurement.Measurement instance) – the pyowm.stationsapi30.measurement.Measurement object to be posted

Returns:

None if creation is successful, an exception otherwise

send_measurements(list_of_measurements)[source]

Posts data about the provided list of Measurement objects to the Station API. The objects may be related to different station IDs.

Parameters:

list_of_measurements (list of pyowm.stationsapi30.measurement.Measurement instances) – list of pyowm.stationsapi30.measurement.Measurement objects to be posted

Returns:

None if creation is successful, an exception otherwise

stations_api_version()[source]
update_station(station)[source]

Updates the Station API record identified by the ID of the provided pyowm.stationsapi30.station.Station object with all of its fields

Parameters:

station (pyowm.stationsapi30.station.Station) – the pyowm.stationsapi30.station.Station object to be updated

Returns:

None if update is successful, an exception otherwise

Module contents