def make_alarm_message(self, channel_name, input_guid, event_type, tmstmp): input_name = BaseUtils.get_object_name_by_guid(input_guid) alarm_messages = {} event_time = datetime.fromtimestamp(tmstmp/1e6) ev_translation = self.events_translation.get(event_type, "Unknown") alarm_messages["alert_message"] = ( "<br><b><font color='red'>{event_type}</font></b><br>{event_time}" "<br>{input_name_text}:<br>{input_name}. <br>{on_channel}: {chan_name}" ).format( event_time=event_time, event_type=ev_translation, input_name_text=loc.gpio.input_name, input_name=input_name, on_channel=loc.gpio.associated_channel, chan_name=channel_name, ) alarm_messages["sms_message"] = ( "{event_type}: {input_name}. {on_channel}: {chan_name}" ).format( event_type=ev_translation, input_name=input_name, on_channel=loc.gpio.associated_channel, chan_name=channel_name, ) alarm_messages["mail_message"] = ( "{event_time}. {event_type}: {input_name}." " {on_channel}: {channel_name}.".format( event_time=event_time, input_name=input_name, event_type=ev_translation, on_channel=loc.gpio.associated_channel, channel_name=channel_name, ) ) return alarm_messages
def execute(self, channel, ts, alarm_messages, *args, **kwargs): """ При распознавании лица на сервере фото из БД и фото распознанного лица из трека лежат в kwargs.get("images") в виде kwargs.get("images") = { "db_image": [bytes_1, bytes_2], "track_image": [bytes_3] } Args: channel (str): channel full guid ts (int): (Trassir 16 digit timestamp) alarm_messages (dict): *args: **kwargs: Returns: """ if self.shot_spam_filter and self.shot_spam_filter.is_same(channel): logger.debug("shot spam filter enabled, break for channel: %s", channel) return ts = int(ts) + int(self.delta * 1e3) if self.online_shot: ts = None if self.save_substream: ts = datetime.now() + timedelta(days=7) channel_name = re.sub( self.spec_symbols, "_", BaseUtils.get_object_name_by_guid(channel), ) zone_name = kwargs.get("zone_name") if zone_name: file_name = "{channel_name}({zone_name}) (%Y.%m.%d %H-%M-%S.%f).jpg".format( channel_name=channel_name, zone_name=zone_name) else: file_name = "{channel_name} (%Y.%m.%d %H-%M-%S.%f).jpg".format( channel_name=channel_name) if self.save_screen: file_path = os.path.join(datetime.now().date().isoformat(), channel_name) full_path = os.path.normpath( os.path.join(self.base_folder, file_path)) else: full_path = self.temp_folder logger.debug("file path for screen: %s", full_path) # shot_saver.ShotSaver task_guid, file_path = self.shot_saver_obj.save( channel, ts, figures=self.figures, file_path=full_path, file_name=file_name, callback=self.send_shots) self._working[task_guid] = { "alarm_messages": alarm_messages, "state": "just_created", "created_ts": int(time.time()), "file_path": file_path, "images": kwargs.get("images"), "channel": channel, }