Skip to content

Commit 3cf6e39

Browse files
authored
small refactor of the slack notification (#487)
* small refactor of the slack notification * add url of the S3 in slack notification
1 parent c45d5c0 commit 3cf6e39

1 file changed

Lines changed: 20 additions & 5 deletions

File tree

src/app/services/slack.py

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
import json
77
import logging
8+
from datetime import datetime
9+
from zoneinfo import ZoneInfo
810

911
import requests
1012

@@ -42,6 +44,11 @@ def notify(self, slack_hook: str, message_detection: str, url: str, camera_name:
4244
raise ValueError("Invalid JSON format for message_detection") from e
4345

4446
azimuth = detection_data.get("azimuth", "Inconnu")
47+
created_at_str = detection_data.get("created_at", "Inconnu")
48+
utc_dt = datetime.fromisoformat(created_at_str)
49+
utc_dt = utc_dt.replace(tzinfo=ZoneInfo("UTC"))
50+
paris_dt = utc_dt.astimezone(ZoneInfo("Europe/Paris"))
51+
4552
if url is not None:
4653
message = {
4754
"text": "Un feu a été detecté !",
@@ -51,11 +58,16 @@ def notify(self, slack_hook: str, message_detection: str, url: str, camera_name:
5158
"block_id": "section567",
5259
"text": {
5360
"type": "mrkdwn",
54-
"text": ":fire: \n\n Nom du site concerné : "
61+
"text": ":date: "
62+
+ paris_dt.strftime("%Y-%m-%d %H:%M:%S")
63+
+ "\n Nom du site concerné : "
5564
+ camera_name
56-
+ "\n Azimuth :"
65+
+ "\n Azimuth de detection : "
5766
+ str(azimuth)
58-
+ "\n https://platform.pyronear.org/",
67+
+ "°"
68+
+ "\n https://platform.pyronear.org/"
69+
+ "\n "
70+
+ url,
5971
},
6072
},
6173
{"type": "image", "image_url": url, "alt_text": "Haunted hotel image"},
@@ -70,10 +82,13 @@ def notify(self, slack_hook: str, message_detection: str, url: str, camera_name:
7082
"block_id": "section567",
7183
"text": {
7284
"type": "mrkdwn",
73-
"text": ":fire: \n\n Nom du site concerné : "
85+
"text": ":date: "
86+
+ paris_dt.strftime("%Y-%m-%d %H:%M:%S")
87+
+ "\n Nom du site concerné : "
7488
+ camera_name
75-
+ "\n Azimuth :"
89+
+ "\n Azimuth de detection : "
7690
+ str(azimuth)
91+
+ "°"
7792
+ "\n https://platform.pyronear.org/",
7893
},
7994
},

0 commit comments

Comments
 (0)