teams-alerter 0.2.2__py3-none-any.whl → 0.2.3__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
teams_alerter/core.py CHANGED
@@ -2,7 +2,7 @@ import json
2
2
  import traceback
3
3
 
4
4
  from google.cloud import pubsub_v1
5
- from .utils import ErrorUtils, DateUtils, format_email_template_horse
5
+ from .utils import ErrorUtils, DateUtils, format_email_template
6
6
 
7
7
 
8
8
  class TeamsAlerter:
@@ -91,4 +91,25 @@ class TeamsAlerter:
91
91
 
92
92
  def format_email_template(self):
93
93
  self.payload["alert_type"].append("email")
94
- self.payload["email_template_html"] = format_email_template_horse()
94
+
95
+ if self.utils["app_name"] == "health_check_check_horses_stats":
96
+ error_info_list = json.loads(self.payload["detail"]["message"])
97
+ table_data = [("ID CHEVAL", "CHAMP", "POSTGRES", "MONGO", "DIFFERENCE")]
98
+ for error_info in error_info_list:
99
+ table_data.append(
100
+ (
101
+ error_info["idCheval"],
102
+ error_info["champ"],
103
+ error_info["postgres"],
104
+ error_info["mongo"],
105
+ error_info["difference"],
106
+ )
107
+ )
108
+
109
+ email_object = "Contrôle DATASTREAM - Fiche cheval"
110
+ email_message = """
111
+ Bonjour, <br>
112
+ Veuillez trouver ci-dessous le tableau récapitulatif du contrôle effectué sur la fiche cheval dans Datastream (champs formFigs et totalPrize) le 25/08/2025 à 13:15:00 UTC.
113
+ """
114
+
115
+ self.payload["email_template_html"] = format_email_template(email_object, email_message, table_data)
teams_alerter/utils.py CHANGED
@@ -31,84 +31,93 @@ class DateUtils:
31
31
  return dt.strftime("%Y-%m-%dT%H:%M:%S") + ".000000000Z"
32
32
 
33
33
 
34
- def format_email_template_horse():
35
- email_object = "Contrôle DATASTREAM - Fiche cheval"
36
- email_message = """
37
- Bonjour, <br>
38
- Veuillez trouver ci-dessous le tableau récapitulatif du contrôle effectué sur la fiche cheval dans Datastream (champs formFigs et totalPrize) le 25/08/2025 à 13:15:00 UTC.
39
- """
34
+ def format_email_template(email_object, email_message, table_data):
40
35
  html = f"""
41
- <table role="presentation" cellpadding="0" cellspacing="0" border="0" width="100%" style="background:#f5f7fb;">
42
- <tr>
43
- <td align="center" style="padding:24px;">
44
- <table role="presentation" cellpadding="0" cellspacing="0" border="0" style="max-width:100%; background:#ffffff; border-radius:8px; border:1px solid #e6e9ef;">
36
+ <html>
37
+ <head lang="fr">
38
+ <meta charset="utf-8">
39
+ <meta name="x-apple-disable-message-reformatting">
40
+ <meta name="viewport" content="width=device-width, initial-scale=1">
41
+ <title>Contrôle datastream</title>
42
+ </head>
43
+ <body style="margin:0; padding:0; background:#f5f7fb;">
44
+ <table role="presentation" cellpadding="0" cellspacing="0" border="0" width="100%" style="background:#f5f7fb;">
45
45
  <tr>
46
- <td style="text-align: center; padding-top: 12px;">
47
- <img style="height: 24px;" src="https://upload.wikimedia.org/wikipedia/fr/f/fd/Logo_Paris_Turf.svg" alt="" srcset="">
48
- </td>
49
- </tr>
46
+ <td align="center" style="padding:24px;">
47
+ <table role="presentation" cellpadding="0" cellspacing="0" border="0" style="max-width:100%; background:#ffffff; border-radius:8px; border:1px solid #e6e9ef;">
48
+ <tr>
49
+ <td style="text-align: center; padding-top: 12px;">
50
+ <img style="height: 24px;" src="https://upload.wikimedia.org/wikipedia/fr/f/fd/Logo_Paris_Turf.svg" alt="" srcset="">
51
+ </td>
52
+ </tr>
50
53
 
51
- <tr>
52
- <td style="padding:24px 24px 12px 24px; font-family:Segoe UI, Arial, sans-serif; font-size:20px; line-height:26px; color:#111827; font-weight:700;">
53
- Objet : {email_object}
54
- </td>
55
- </tr>
54
+ <tr>
55
+ <td style="padding:24px 24px 12px 24px; font-family:Segoe UI, Arial, sans-serif; font-size:20px; line-height:26px; color:#111827; font-weight:700;">
56
+ Objet : {email_object}
57
+ </td>
58
+ </tr>
56
59
 
57
- <tr>
58
- <td style="padding:0 24px 16px 24px; font-family:Segoe UI, Arial, sans-serif; font-size:14px; line-height:20px; color:#4b5563;">
59
- {email_message}
60
- </td>
61
- </tr>
60
+ <tr>
61
+ <td style="padding:0 24px 16px 24px; font-family:Segoe UI, Arial, sans-serif; font-size:14px; line-height:20px; color:#4b5563;">
62
+ {email_message}
63
+ </td>
64
+ </tr>
62
65
 
63
- <tr>
64
- <td style="padding:0 16px 24px 16px;">
65
- <table role="presentation" cellpadding="0" cellspacing="0" border="0" width="100%" style="border-collapse:collapse; font-family:Segoe UI, Arial, sans-serif;">
66
- <!-- Header -->
67
- <tr>
68
- <th align="left" style="padding:12px 10px; font-size:12px; line-height:16px; color:#374151; text-transform:uppercase; letter-spacing:.5px; border-bottom:2px solid #e5e7eb; background:#f9fafb;">ID cheval</th>
69
- <th align="left" style="padding:12px 10px; font-size:12px; line-height:16px; color:#374151; text-transform:uppercase; letter-spacing:.5px; border-bottom:2px solid #e5e7eb; background:#f9fafb;">Champ</th>
70
- <th align="left" style="padding:12px 10px; font-size:12px; line-height:16px; color:#374151; text-transform:uppercase; letter-spacing:.5px; border-bottom:2px solid #e5e7eb; background:#f9fafb;">Postgres</th>
71
- <th align="left" style="padding:12px 10px; font-size:12px; line-height:16px; color:#374151; text-transform:uppercase; letter-spacing:.5px; border-bottom:2px solid #e5e7eb; background:#f9fafb;">Mongo</th>
72
- <th align="left" style="padding:12px 10px; font-size:12px; line-height:16px; color:#374151; text-transform:uppercase; letter-spacing:.5px; border-bottom:2px solid #e5e7eb; background:#f9fafb;">Différence</th>
73
- </tr>
74
- <!-- Row 1 -->
75
- <tr>
76
- <td style="padding:10px; font-size:14px; line-height:20px; color:#111827; border-bottom:1px solid #bbbbbb;">12345</td>
77
- <td style="padding:10px; font-size:14px; line-height:20px; color:#111827; border-bottom:1px solid #bbbbbb;">formFigs</td>
78
- <td style="padding:10px; font-size:14px; line-height:20px; color:#111827; border-bottom:1px solid #bbbbbb;">8a 6a Da (24) 7a 8a 10a ...</td>
79
- <td style="padding:10px; font-size:14px; line-height:20px; color:#111827; border-bottom:1px solid #bbbbbb;">Da (24) 7a 8a 10a ...</td>
80
- <td style="padding:10px; font-size:14px; line-height:20px; color:#111827; border-bottom:1px solid #bbbbbb;">Début tronqué (8a 6a manquants)</td>
81
- </tr>
82
- <!-- Row 2 -->
83
- <tr>
84
- <td style="padding:10px; font-size:14px; line-height:20px; color:#111827;">123456</td>
85
- <td style="padding:10px; font-size:14px; line-height:20px; color:#111827;">totalPrize</td>
86
- <td style="padding:10px; font-size:14px; line-height:20px; color:#111827;">108220</td>
87
- <td style="padding:10px; font-size:14px; line-height:20px; color:#111827;">108222</td>
88
- <td style="padding:10px; font-size:14px; line-height:20px; color:#111827;">-2</td>
89
- </tr>
90
- </table>
91
- </td>
92
- </tr>
66
+ <tr>
67
+ <td style="padding:0 24px 16px 24px; font-family:Segoe UI, Arial, sans-serif; font-size:14px; line-height:20px; color:#4b5563;">
68
+ Env: <strong>INT</strong> <br>
69
+ Timestamp: <time datetime="2025-08-25T13:15:00Z">2025-08-25T13:15:00Z</time> <br>
70
+ Champs: <strong>formFigs et/ou totalPrize</strong>
71
+ </td>
72
+ </tr>
93
73
 
94
- <tr>
95
- <td style="padding:0 24px 16px 24px; font-family:Segoe UI, Arial, sans-serif; font-size:14px; line-height:20px; color:#4b5563;">
96
- Cordialement,
97
- </td>
98
- </tr>
74
+ <tr>
75
+ <td style="padding:0 16px 24px 16px;">
76
+ {build_html_table(table_data)}
77
+ </td>
78
+ </tr>
99
79
 
100
- <tr>
101
- <td style="padding:0 24px 24px 24px; font-family:Segoe UI, Arial, sans-serif; font-size:12px; line-height:18px; color:#6b7280;">
102
- <div style="border-top:1px solid #eef2f7; padding-top:12px;text-align: center;">
103
- Message automatique – ne pas répondre. <br>
104
- © 2025 Paris-Turf – Tous droits réservés <br>
105
- <a href="https://www.paris-turf.com">www.paris-turf.com</a>
106
- </div>
107
- </td>
80
+ <tr>
81
+ <td style="padding:0 24px 16px 24px; font-family:Segoe UI, Arial, sans-serif; font-size:14px; line-height:20px; color:#4b5563;">
82
+ Cordialement,
83
+ </td>
84
+ </tr>
85
+
86
+ <tr>
87
+ <td style="padding:0 24px 24px 24px; font-family:Segoe UI, Arial, sans-serif; font-size:12px; line-height:18px; color:#6b7280;">
88
+ <div style="border-top:1px solid #eef2f7; padding-top:12px;text-align: center;">
89
+ Message automatique – ne pas répondre. <br>
90
+ © 2025 Paris-Turf – Tous droits réservés <br>
91
+ <a href="https://www.paris-turf.com">www.paris-turf.com</a>
92
+ </div>
93
+ </td>
94
+ </tr>
95
+ </table>
96
+ </td>
108
97
  </tr>
109
98
  </table>
110
- </td>
111
- </tr>
112
- </table>
99
+ </body>
100
+ </html>
113
101
  """
114
102
  return html
103
+
104
+
105
+ def build_html_table(table_data: list):
106
+ html_table = '<table role="presentation" cellpadding="0" cellspacing="0" border="0" width="100%" style="border-collapse:collapse; font-family:Segoe UI, Arial, sans-serif;">'
107
+
108
+ # format header
109
+ html_table += "<tr>"
110
+ for header in table_data[0]:
111
+ html_table += f'<th style="padding:10px; font-size:14px; line-height:20px; color:#111827; border-bottom:1px solid #bbbbbb;">{header}</th>'
112
+ html_table += "</tr>"
113
+
114
+ # format rows
115
+ for row in table_data[1:]:
116
+ html_table += "<tr>"
117
+ for cell in row:
118
+ html_table += f'<td style="padding:10px; font-size:14px; line-height:20px; color:#111827; border-bottom:1px solid #bbbbbb;">{cell}</td>'
119
+ html_table += "</tr>"
120
+
121
+ html_table += "</table>"
122
+
123
+ return html_table
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: teams-alerter
3
- Version: 0.2.2
3
+ Version: 0.2.3
4
4
  Summary: Module pour envoyer des alertes Teams via Pub/Sub
5
5
  Author-email: Toki <t.bakotondrabe-ext@paris-turf.com>
6
6
  License: MIT
@@ -0,0 +1,7 @@
1
+ teams_alerter/__init__.py,sha256=J6zyyTfUNVElXD0wsTqBwp-VtcApbzYGUPpChrdcbpY,131
2
+ teams_alerter/core.py,sha256=hZwY81vf3LR7bhHgUV6XYSh1tany_Coy5aEguv5-sbQ,4656
3
+ teams_alerter/utils.py,sha256=EzmGSTsWC8UwWyDVgL_U5mw9MY9Ll19aZ_VGPZdSRZI,5772
4
+ teams_alerter-0.2.3.dist-info/METADATA,sha256=mCkPNerF-wSGyNtk4sCQWYXnjGeftnKUgBo2b25TokU,2194
5
+ teams_alerter-0.2.3.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
6
+ teams_alerter-0.2.3.dist-info/top_level.txt,sha256=Qt8-VgHT7YPTbMzYkAomK9itC-w4YpV7IJ5X6b-TC-4,14
7
+ teams_alerter-0.2.3.dist-info/RECORD,,
@@ -1,7 +0,0 @@
1
- teams_alerter/__init__.py,sha256=J6zyyTfUNVElXD0wsTqBwp-VtcApbzYGUPpChrdcbpY,131
2
- teams_alerter/core.py,sha256=5KEH5BxAhRizcsAq7oSzdgrRMFsBqMPW577trAdchfE,3653
3
- teams_alerter/utils.py,sha256=YxFujHeq64EbB-ra3ShSM-0SrCsXxWODlAn7Wy6oxzY,6687
4
- teams_alerter-0.2.2.dist-info/METADATA,sha256=6DemT05MGWOGxLDGxqyQ29bPtlR2M9SifPh-FASRAYA,2194
5
- teams_alerter-0.2.2.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
6
- teams_alerter-0.2.2.dist-info/top_level.txt,sha256=Qt8-VgHT7YPTbMzYkAomK9itC-w4YpV7IJ5X6b-TC-4,14
7
- teams_alerter-0.2.2.dist-info/RECORD,,