本文整理汇总了Python中utility.Utility.generate_base_event方法的典型用法代码示例。如果您正苦于以下问题:Python Utility.generate_base_event方法的具体用法?Python Utility.generate_base_event怎么用?Python Utility.generate_base_event使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类utility.Utility
的用法示例。
在下文中一共展示了Utility.generate_base_event方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: build_alert
# 需要导入模块: from utility import Utility [as 别名]
# 或者: from utility.Utility import generate_base_event [as 别名]
def build_alert(self, alert_id, alert_message, location=None):
"""Build the actual alert and returns it, formatted.
DEPRECATION NOTICE: The 'alert_id' field has been introduced for
better readability. It's currently set to be the same as 'id'.
At some point in the future, the 'id' field will be removed.
Args:
alert_id (int): The ID of the alert you want to build
alert_message (str): The message to be embedded in the alert.
Returns:
tuple: Position 0 contains the string 'sitch_alert'. Position 1
contains the alert and metadata.
"""
if location is None:
print("AlertManager: No geo for alarm: %s" % str(alert_message))
location = {"type": "Point", "coordinates": [0, 0]}
elif Utility.validate_geojson(location) is False:
print("AlertManager: Invalid geojson %s for: %s" % (location,
alert_message))
location = {"type": "Point", "coordinates": [0, 0]}
lat = location["coordinates"][1]
lon = location["coordinates"][0]
gmaps_url = Utility.create_gmaps_link(lat, lon)
message = Utility.generate_base_event()
message["alert_id"] = alert_id
message["id"] = alert_id
message["alert_type"] = self.get_alert_type(alert_id)
message["event_type"] = "sitch_alert"
message["details"] = ("%s %s" % (alert_message, gmaps_url))
message["location"] = location
retval = ("sitch_alert", message)
return retval