teams-alerter 0.2.6__py3-none-any.whl → 0.2.8__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
@@ -1,5 +1,6 @@
1
1
  import json
2
2
  import traceback
3
+ import datetime
3
4
 
4
5
  from google.cloud import pubsub_v1
5
6
  from .utils import ErrorUtils, DateUtils, format_email_template, is_json
@@ -54,11 +55,11 @@ class TeamsAlerter:
54
55
  "health_check_check_pg_wal_slot",
55
56
  "health_check_check_meetings_ids",
56
57
  "health_check_check_races_ids",
57
- "health_check_check_partants_data",
58
58
  "health_check_check_runners_ids",
59
59
  "health_check_check_processing_queue_ids",
60
60
  ],
61
61
  "email": [
62
+ "health_check_check_partants_data",
62
63
  "health_check_check_horses_stats",
63
64
  ],
64
65
  }
@@ -124,6 +125,55 @@ class TeamsAlerter:
124
125
  """,
125
126
  ]
126
127
 
127
- self.payload["email_template_html"] = format_email_template(email_object, email_messages, table_data)
128
+ self.payload["email_template_html"] = format_email_template(
129
+ email_object, email_messages, table_data, self.utils["app_name"]
130
+ )
131
+ else:
132
+ print(
133
+ "⚠ ERREUR INTERNE : error_message health_check_check_horses_stats n'est pas un JSON valide :",
134
+ self.payload["detail"]["message"],
135
+ )
136
+
137
+ elif self.utils["app_name"] == "health_check_check_partants_data":
138
+ if is_json(self.payload["detail"]["message"]):
139
+ error_info_list = json.loads(self.payload["detail"]["message"])
140
+
141
+ table_data = []
142
+ for error_info in error_info_list["data"]:
143
+ table_data.append(
144
+ (
145
+ error_info["idCourse"],
146
+ error_info["dateCourse"],
147
+ error_info["nbInitialRunners_postgres"],
148
+ error_info["nbInitialRunners_mongo"],
149
+ error_info["nbNonRunners_postgres"],
150
+ error_info["nbNonRunners_mongo"],
151
+ error_info["nonRunners_postgres"],
152
+ error_info["nonRunners_mongo"],
153
+ error_info["nbRunners_postgres"],
154
+ error_info["nbRunners_mongo"],
155
+ )
156
+ )
157
+ email_object = "Contrôle DATASTREAM - Partants (COURSES)"
158
+ self.payload["email_object"] = email_object
159
+
160
+ email_messages = [
161
+ f"""
162
+ Bonjour, <br>
163
+ Veuillez trouver ci-dessous le tableau récapitulatif du contrôle effectué sur les partants des courses du {datetime.date.today().strftime("%d/%m/%Y")} dans Datastream.
164
+ """,
165
+ f"""
166
+ Env: <strong>{self.utils["env"]}</strong> <br>
167
+ Timestamp: {DateUtils.get_str_utc_timestamp()} <br>
168
+ Table name: <strong>tb_course</strong>
169
+ """,
170
+ ]
171
+
172
+ self.payload["email_template_html"] = format_email_template(
173
+ email_object, email_messages, table_data, self.utils["app_name"]
174
+ )
128
175
  else:
129
- print("⚠ ERREUR INTERNE : error_message n'est pas un JSON valide :", self.payload["detail"]["message"])
176
+ print(
177
+ "⚠ ERREUR INTERNE : error_message health_check_check_partants_data n'est pas un JSON valide :",
178
+ self.payload["detail"]["message"],
179
+ )
teams_alerter/utils.py CHANGED
@@ -32,7 +32,7 @@ class DateUtils:
32
32
  return dt.strftime("%Y-%m-%dT%H:%M:%S") + ".000000000Z"
33
33
 
34
34
 
35
- def format_email_template(email_object, email_messages, table_data):
35
+ def format_email_template(email_object, email_messages, table_data, app_name):
36
36
  html = f"""
37
37
  <html>
38
38
  <head lang="fr">
@@ -62,7 +62,7 @@ def format_email_template(email_object, email_messages, table_data):
62
62
 
63
63
  <tr>
64
64
  <td style="padding:0 16px 24px 16px;">
65
- {build_html_table(table_data)}
65
+ {build_html_table(table_data, app_name)}
66
66
  </td>
67
67
  </tr>
68
68
 
@@ -91,20 +91,60 @@ def format_email_template(email_object, email_messages, table_data):
91
91
  return html
92
92
 
93
93
 
94
- def build_html_table(table_data: list):
94
+ def build_html_table(table_data: list, app_name: str):
95
+ if app_name == "health_check_check_horses_stats":
96
+ html_table = '<table role="presentation" cellpadding="0" cellspacing="0" border="0" width="100%" style="border-collapse:collapse; font-family:Segoe UI, Arial, sans-serif;">'
97
+
98
+ # format header
99
+ html_table += "<tr>"
100
+ for header in table_data[0]:
101
+ html_table += f'<th style="padding:10px; font-size:14px; line-height:20px; color:#111827; border-bottom:1px solid #bbbbbb;">{header}</th>'
102
+ html_table += "</tr>"
103
+
104
+ # format rows
105
+ for row in table_data[1:]:
106
+ html_table += "<tr>"
107
+ for cell in row:
108
+ html_table += f'<td style="padding:10px; font-size:14px; line-height:20px; color:#111827; border-bottom:1px solid #bbbbbb;">{cell}</td>'
109
+ html_table += "</tr>"
110
+
111
+ html_table += "</table>"
112
+
113
+ return html_table
114
+
115
+ elif app_name == "health_check_check_partants_data":
116
+ return build_html_table_partants_course(table_data)
117
+
118
+
119
+ def build_html_table_partants_course(table_data: list):
95
120
  html_table = '<table role="presentation" cellpadding="0" cellspacing="0" border="0" width="100%" style="border-collapse:collapse; font-family:Segoe UI, Arial, sans-serif;">'
96
121
 
97
122
  # format header
98
- html_table += "<tr>"
99
- for header in table_data[0]:
100
- html_table += f'<th style="padding:10px; font-size:14px; line-height:20px; color:#111827; border-bottom:1px solid #bbbbbb;">{header}</th>'
101
- html_table += "</tr>"
102
-
123
+ html_table += """
124
+ <tr>
125
+ <th align="center" style="padding:12px 10px; font-size:12px; line-height:16px; color:#374151; text-transform:uppercase; letter-spacing:.5px; border:2px solid #e5e7eb; background:#f9fafb;" rowspan="2">ID Course</th>
126
+ <th align="center" style="padding:12px 10px; font-size:12px; line-height:16px; color:#374151; text-transform:uppercase; letter-spacing:.5px; border:2px solid #e5e7eb; background:#f9fafb;" rowspan="2">Date Course</th>
127
+ <th align="center" style="padding:12px 10px; font-size:12px; line-height:16px; color:#374151; text-transform:uppercase; letter-spacing:.5px; border:2px solid #e5e7eb; background:#f9fafb;" colspan="2">NB initial runners</th>
128
+ <th align="center" style="padding:12px 10px; font-size:12px; line-height:16px; color:#374151; text-transform:uppercase; letter-spacing:.5px; border:2px solid #e5e7eb; background:#f9fafb;" colspan="2">NB non runners</th>
129
+ <th align="center" style="padding:12px 10px; font-size:12px; line-height:16px; color:#374151; text-transform:uppercase; letter-spacing:.5px; border:2px solid #e5e7eb; background:#f9fafb;" colspan="2">Non runners</th>
130
+ <th align="center" style="padding:12px 10px; font-size:12px; line-height:16px; color:#374151; text-transform:uppercase; letter-spacing:.5px; border:2px solid #e5e7eb; background:#f9fafb;" colspan="2">NB runners</th>
131
+ </tr>
132
+ <tr>
133
+ <th align="left" style="padding:12px 10px; font-size:12px; line-height:16px; color:#374151; text-transform:uppercase; letter-spacing:.5px; border:2px solid #e5e7eb; background:#f9fafb;">Postgres</th>
134
+ <th align="left" style="padding:12px 10px; font-size:12px; line-height:16px; color:#374151; text-transform:uppercase; letter-spacing:.5px; border:2px solid #e5e7eb; background:#f9fafb;">Mongo</th>
135
+ <th align="left" style="padding:12px 10px; font-size:12px; line-height:16px; color:#374151; text-transform:uppercase; letter-spacing:.5px; border:2px solid #e5e7eb; background:#f9fafb;">Postgres</th>
136
+ <th align="left" style="padding:12px 10px; font-size:12px; line-height:16px; color:#374151; text-transform:uppercase; letter-spacing:.5px; border:2px solid #e5e7eb; background:#f9fafb;">Mongo</th>
137
+ <th align="left" style="padding:12px 10px; font-size:12px; line-height:16px; color:#374151; text-transform:uppercase; letter-spacing:.5px; border:2px solid #e5e7eb; background:#f9fafb;">Postgres</th>
138
+ <th align="left" style="padding:12px 10px; font-size:12px; line-height:16px; color:#374151; text-transform:uppercase; letter-spacing:.5px; border:2px solid #e5e7eb; background:#f9fafb;">Mongo</th>
139
+ <th align="left" style="padding:12px 10px; font-size:12px; line-height:16px; color:#374151; text-transform:uppercase; letter-spacing:.5px; border:2px solid #e5e7eb; background:#f9fafb;">Postgres</th>
140
+ <th align="left" style="padding:12px 10px; font-size:12px; line-height:16px; color:#374151; text-transform:uppercase; letter-spacing:.5px; border:2px solid #e5e7eb; background:#f9fafb;">Mongo</th>
141
+ </tr>
142
+ """
103
143
  # format rows
104
- for row in table_data[1:]:
144
+ for row in table_data:
105
145
  html_table += "<tr>"
106
146
  for cell in row:
107
- html_table += f'<td style="padding:10px; font-size:14px; line-height:20px; color:#111827; border-bottom:1px solid #bbbbbb;">{cell}</td>'
147
+ html_table += f'<td style="padding:10px; font-size:14px; line-height:20px; color:#111827; border:1px solid #bbbbbb;">{cell}</td>'
108
148
  html_table += "</tr>"
109
149
 
110
150
  html_table += "</table>"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: teams-alerter
3
- Version: 0.2.6
3
+ Version: 0.2.8
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,9 @@
1
+ teams_alerter/__init__.py,sha256=J6zyyTfUNVElXD0wsTqBwp-VtcApbzYGUPpChrdcbpY,131
2
+ teams_alerter/core.py,sha256=UrlZ3QTiuRZ_e8hDRRqw-HSqF2vgqBqd4K91o3U_KtI,7863
3
+ teams_alerter/utils.py,sha256=h96evthyIezxKxBauHxevVslyHSE_LJ0h6DcKy6KNBs,9619
4
+ tests/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
5
+ tests/test_core.py,sha256=Bd3rxUUXAYM3oKK4Gs5u2AF4-Di5oSmXsMeHINfEHyM,3089
6
+ teams_alerter-0.2.8.dist-info/METADATA,sha256=CXbVwzzAxp6lcnSkKfsQ-YoPtB4iRDqdu19KGpENukQ,2194
7
+ teams_alerter-0.2.8.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
8
+ teams_alerter-0.2.8.dist-info/top_level.txt,sha256=eLk39V0LcwZmxaC5MkgLKvTLeBaox3XkfSvXxm7GVik,20
9
+ teams_alerter-0.2.8.dist-info/RECORD,,
@@ -1,9 +0,0 @@
1
- teams_alerter/__init__.py,sha256=J6zyyTfUNVElXD0wsTqBwp-VtcApbzYGUPpChrdcbpY,131
2
- teams_alerter/core.py,sha256=XSsFRdTcHIbH2ec7KavNPnl2DuNQA2UIMO5qV4wIGMM,5467
3
- teams_alerter/utils.py,sha256=lA_BATVjYEEreTiiCIUbT_KqOxi0XUiMCUE5qkXpEhg,5586
4
- tests/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
5
- tests/test_core.py,sha256=Bd3rxUUXAYM3oKK4Gs5u2AF4-Di5oSmXsMeHINfEHyM,3089
6
- teams_alerter-0.2.6.dist-info/METADATA,sha256=bVygo8dVEMp0SJ8NPmwRYjcHxEs1I2TAOxjqg7kLsrM,2194
7
- teams_alerter-0.2.6.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
8
- teams_alerter-0.2.6.dist-info/top_level.txt,sha256=eLk39V0LcwZmxaC5MkgLKvTLeBaox3XkfSvXxm7GVik,20
9
- teams_alerter-0.2.6.dist-info/RECORD,,