pyowm.alertapi30 package¶
Submodules¶
pyowm.alertapi30.alert_manager module¶
- class pyowm.alertapi30.alert_manager.AlertManager(API_key, config)[source]¶
Bases:
objectA manager objects that provides a full interface to OWM Alert API. It implements CRUD methods on Trigger entities and read/deletion of related Alert objects
- Parameters:
API_key (str) – the OWM Weather API key
config (dict) – the configuration dictionary
- Returns:
an AlertManager instance
- Raises:
AssertionError when no API Key is provided
- create_trigger(start, end, conditions, area, alert_channels=None)[source]¶
Create a new trigger on the Alert API with the given parameters :param start: time object representing the time when the trigger begins to be checked :type start: int,
datetime.datetimeor ISO8601-formatted string :param end: time object representing the time when the trigger ends to be checked :type end: int,datetime.datetimeor ISO8601-formatted string :param conditions: the Condition objects representing the set of checks to be done on weather variables :type conditions: list of pyowm.utils.alertapi30.Condition instances :param area: the geographic are over which conditions are checked: it can be composed by multiple geoJSON types :type area: list of geoJSON types :param alert_channels: the alert channels through which alerts originating from this Trigger can be consumed. Defaults to OWM API polling :type alert_channels: list of pyowm.utils.alertapi30.AlertChannel instances :returns: a Trigger instance :raises: ValueError when start or end epochs are None or when end precedes start or when conditions or area are empty collections
- delete_alert(alert)[source]¶
Deletes the specified alert from the Alert API :param alert: the alert to be deleted :type alert: pyowm.alertapi30.alert.Alert` :return:
Noneif the deletion was successful, an error otherwise
- delete_all_alerts_for(trigger)[source]¶
Deletes all of the alert that were fired for the specified Trigger :param trigger: the trigger whose alerts are to be cleared :type trigger: pyowm.alertapi30.trigger.Trigger :return: None if deletion is successful, an exception otherwise
- delete_trigger(trigger)[source]¶
Deletes from the Alert API the trigger record identified by the ID of the provided pyowm.alertapi30.trigger.Trigger, along with all related alerts
- Parameters:
trigger (pyowm.alertapi30.trigger.Trigger) – the pyowm.alertapi30.trigger.Trigger object to be deleted
- Returns:
None if deletion is successful, an exception otherwise
- get_alert(alert_id, trigger)[source]¶
Retrieves info about the alert record on the Alert API that has the specified ID and belongs to the specified parent Trigger object :param trigger: the parent trigger :type trigger: pyowm.alertapi30.trigger.Trigger :param alert_id: the ID of the alert :type alert_id pyowm.alertapi30.alert.Alert :return: an pyowm.alertapi30.alert.Alert instance
- get_alerts_for(trigger)[source]¶
Retrieves all of the alerts that were fired for the specified Trigger :param trigger: the trigger :type trigger: pyowm.alertapi30.trigger.Trigger :return: list of pyowm.alertapi30.alert.Alert objects
- get_trigger(trigger_id)[source]¶
Retrieves the named trigger from the Weather Alert API.
- Parameters:
trigger_id (str) – the ID of the trigger
- Returns:
a pyowm.alertapi30.trigger.Trigger instance
- get_triggers()[source]¶
Retrieves all of the user’s triggers that are set on the Weather Alert API.
- Returns:
list of pyowm.alertapi30.trigger.Trigger objects
- update_trigger(trigger)[source]¶
Updates on the Alert API the trigger record having the ID of the specified Trigger object: the remote record is updated with data from the local Trigger object.
- Parameters:
trigger (pyowm.alertapi30.trigger.Trigger) – the Trigger with updated data
- Returns:
Noneif update is successful, an error otherwise
pyowm.alertapi30.alert module¶
- class pyowm.alertapi30.alert.Alert(id, trigger_id, met_conditions, coordinates, last_update=None)[source]¶
Bases:
objectRepresents the situation happening when any of the conditions bound to a Trigger is met. Whenever this happens, an Alert object is created (or updated) and is bound to its parent Trigger. The trigger can then be polled to check what alerts have been fired on it. :param id: unique alert identifier :type name: str :param trigger_id: link back to parent Trigger :type trigger_id: str :param met_conditions: list of dict, each one referring to a Condition obj bound to the parent Trigger and reporting the actual measured values that made this Alert fire :type met_conditions: list of dict :param coordinates: dict representing the geocoordinates where the Condition triggering the Alert was met :type coordinates: dict :param last_update: epoch of the last time when this Alert has been fired :type last_update: int
- classmethod from_dict(the_dict)[source]¶
Parses a Alert 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 Alert instance or
Noneif no data is available- Raises:
ParseAPIResponseError if it is impossible to find or parse the data needed to build the result
- class pyowm.alertapi30.alert.AlertChannel(name)[source]¶
Bases:
objectBase class representing a channel through which one can acknowledge that a weather alert has been issued. Examples: OWM API polling, push notifications, email notifications, etc. This feature is yet to be implemented by the OWM API. :param name: name of the channel :type name: str :returns: an AlertChannel instance
pyowm.alertapi30.condition module¶
- class pyowm.alertapi30.condition.Condition(weather_param, operator, amount, id=None)[source]¶
Bases:
objectObject representing a condition to be checked on a specific weather parameter. A condition is given when comparing the weather parameter against a numerical value with respect to an operator. Allowed weather params and operators are specified by the pyowm.utils.alertapi30.WeatherParametersEnum and pyowm.utils.alertapi30.OperatorsEnum enumerator classes. :param weather_param: the weather variable to be checked (eg. TEMPERATURE, CLOUDS, …) :type weather_param: str :param operator: the comparison operator to be applied to the weather variable (eg. GREATER_THAN, EQUAL, …) :type operator: str :param amount: comparison value :type amount: int or float :param id: optional unique ID for this Condition instance :type id: str :returns: a Condition instance :raises: AssertionError when either the weather param has wrong type or the operator has wrong type or the amount has wrong type
pyowm.alertapi30.enums module¶
- class pyowm.alertapi30.enums.AlertChannelsEnum[source]¶
Bases:
objectAllowed alert channels
- OWM_API_POLLING = <pyowm.alertapi30.alert.AlertChannel - name: OWM API POLLING>¶
- class pyowm.alertapi30.enums.OperatorsEnum[source]¶
Bases:
objectAllowed comparison operators for condition checking upon weather parameters
- EQUAL = '$eq'¶
- GREATER_THAN = '$gt'¶
- GREATER_THAN_EQUAL = '$gte'¶
- LESS_THAN = '$lt'¶
- LESS_THAN_EQUAL = '$lte'¶
- NOT_EQUAL = '$ne'¶
pyowm.alertapi30.trigger module¶
- class pyowm.alertapi30.trigger.Trigger(start_after_millis, end_after_millis, conditions, area, alerts=None, alert_channels=None, id=None)[source]¶
Bases:
objectObject representing a the check if a set of weather conditions are met on a given geographical area: each condition is a rule on the value of a given weather parameter (eg. humidity, temperature, etc). Whenever a condition from a Trigger is met, the OWM API crates an alert and binds it to the the Trigger. A Trigger is the local proxy for the corresponding entry on the OWM API, therefore it can get ouf of sync as time goes by and conditions are met: it’s up to you to “refresh” the local trigger by using a pyowm.utils.alertapi30.AlertManager instance. :param start_after_millis: how many milliseconds after the trigger creation the trigger begins to be checked :type start_after_millis: int :param end_after_millis: how many milliseconds after the trigger creation the trigger ends to be checked :type end_after_millis: int :param alerts: the Alert objects representing the alerts that have been fired for this Trigger so far. Defaults to None :type alerts: list of pyowm.utils.alertapi30.Alert instances :param conditions: the Condition objects representing the set of checks to be done on weather variables :type conditions: list of pyowm.utils.alertapi30.Condition instances :param area: the geographic are over which conditions are checked: it can be composed by multiple geoJSON types :type area: list of geoJSON types :param alert_channels: the alert channels through which alerts originating from this Trigger can be consumed. Defaults to OWM API polling :type alert_channels: list of pyowm.utils.alertapi30.AlertChannel instances :param id: optional unique ID for this Trigger instance :type id: str :returns: a Trigger instance :raises: ValueError when start or end epochs are None or when end precedes start or when conditions or area are empty collections
- get_alert(alert_id)[source]¶
Returns the Alert of this Trigger having the specified ID :param alert_id: str, the ID of the alert :return: Alert instance
- get_alerts_on(weather_param)[source]¶
Returns all the Alert objects of this Trigger that refer to the specified weather parameter (eg. ‘temp’, ‘pressure’, etc.). The allowed weather params are the ones enumerated by class pyowm.alertapi30.enums.WeatherParametersEnum :param weather_param: str, values in pyowm.alertapi30.enums.WeatherParametersEnum :return: list of Alert instances
- get_alerts_since(timestamp)[source]¶
Returns all the Alert objects of this Trigger that were fired since the specified timestamp. :param timestamp: time object representing the point in time since when alerts have to be fetched :type timestamp: int,
datetime.datetimeor ISO8601-formatted string :return: list of Alert instances