(20250122) Work reminder cron progressing well.
This commit is contained in:
+116
-48
@@ -346,6 +346,7 @@ async def send_reminders_by_chat(chat_df: pd.DataFrame) -> None:
|
||||
|
||||
# Start with blank variables:
|
||||
log_id = None
|
||||
api_message = None
|
||||
|
||||
# Get a list of unique token-keys:
|
||||
unique_token_keys = chat_df["tokenKey"].unique().tolist()
|
||||
@@ -378,6 +379,7 @@ async def send_reminders_by_chat(chat_df: pd.DataFrame) -> None:
|
||||
|
||||
# Get the log id from the response:
|
||||
log_id = response.json()["logId"]
|
||||
api_message = response.json()["message"]
|
||||
|
||||
# If the API call failed:
|
||||
response.raise_for_status()
|
||||
@@ -390,7 +392,11 @@ async def send_reminders_by_chat(chat_df: pd.DataFrame) -> None:
|
||||
# Send out an alert if needed:
|
||||
if exception is not None:
|
||||
await send_telegram(
|
||||
message = f"*Reminders For Work (Chat)*\n\nException: `{exception}`\n\nLog Id: `{log_id}`",
|
||||
message = (
|
||||
f"*Reminders For Work (Chat)*\n\nException: `{exception}`\n\n"
|
||||
f"Message: `{api_message}`\n\n"
|
||||
f"Log Id: `{log_id}`"
|
||||
),
|
||||
message_type = "error"
|
||||
)
|
||||
|
||||
@@ -398,6 +404,64 @@ async def send_reminders_by_chat(chat_df: pd.DataFrame) -> None:
|
||||
# ---------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
async def send_one_reminder_by_mail(reminder_row) -> None:
|
||||
|
||||
# Start with blank variables:
|
||||
log_id = None
|
||||
api_message = None
|
||||
|
||||
# Create the input(s) needed for making the API call:
|
||||
input_json = {
|
||||
"tokenKey": reminder_row["tokenKey"],
|
||||
"to": [reminder_row["to"]],
|
||||
"subject": f"Reminder for Work - {datetime.datetime.now().strftime('%d/%m/%Y')}",
|
||||
"body": [
|
||||
{
|
||||
"type": "html",
|
||||
"part": {
|
||||
"content": reminder_row["content"]
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
# We are now ready to make the API call:
|
||||
exception = None
|
||||
try:
|
||||
|
||||
# Make the API call:
|
||||
response = await http_client.post(
|
||||
url = r"https://api.thecaoffice.com/converse/mail",
|
||||
json = input_json
|
||||
)
|
||||
|
||||
# Get the log id from the response:
|
||||
log_id = response.json()["logId"]
|
||||
api_message = response.json()["message"]
|
||||
|
||||
# If the API call failed:
|
||||
response.raise_for_status()
|
||||
|
||||
# If the API call goes wrong:
|
||||
except Exception as e:
|
||||
exception = e
|
||||
printer(exception)
|
||||
|
||||
# Send out an alert if needed:
|
||||
if exception is not None:
|
||||
await send_telegram(
|
||||
message = (
|
||||
f"*Reminders For Work (Mail)*\n\nException: `{exception}`\n\n"
|
||||
f"Message: `{api_message}`\n\n"
|
||||
f"Log Id: `{log_id}`"
|
||||
),
|
||||
message_type = "error"
|
||||
)
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
async def send_reminders_by_mail(mail_df: pd.DataFrame) -> None:
|
||||
|
||||
"""
|
||||
@@ -406,54 +470,58 @@ async def send_reminders_by_mail(mail_df: pd.DataFrame) -> None:
|
||||
:return: None
|
||||
"""
|
||||
|
||||
# Start with blank variables:
|
||||
log_id = None
|
||||
# Iterate over all the rows and create mail-sending tasks:
|
||||
tasks = [send_one_reminder_by_mail(row) for index, row in mail_df.iterrows()]
|
||||
await asyncio.gather(*tasks)
|
||||
# for index, row in mail_df.iterrows():
|
||||
|
||||
# Iterate over all the rows and send out the mails:
|
||||
for index, row in mail_df.iterrows():
|
||||
|
||||
# Create the input(s) needed for making the API call:
|
||||
input_json = {
|
||||
"tokenKey": row["tokenKey"],
|
||||
"to": [row["to"]],
|
||||
"subject": f"Reminder for Work - {datetime.datetime.now().strftime('%d/%m/%Y')}",
|
||||
"body": [
|
||||
{
|
||||
"type": "html",
|
||||
"part": {
|
||||
"content": row["content"]
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
# We are now ready to make the API call:
|
||||
exception = None
|
||||
try:
|
||||
|
||||
# Make the API call:
|
||||
response = await http_client.post(
|
||||
url = r"https://api.thecaoffice.com/converse/mail",
|
||||
json = input_json
|
||||
)
|
||||
|
||||
# Get the log id from the response:
|
||||
log_id = response.json()["logId"]
|
||||
|
||||
# If the API call failed:
|
||||
response.raise_for_status()
|
||||
|
||||
# If the API call goes wrong:
|
||||
except Exception as e:
|
||||
exception = e
|
||||
printer(exception)
|
||||
|
||||
# Send out an alert if needed:
|
||||
if exception is not None:
|
||||
await send_telegram(
|
||||
message = f"*Reminders For Work (Mail)*\n\nException: `{exception}`\n\nLog Id: `{log_id}`",
|
||||
message_type = "error"
|
||||
)
|
||||
# # Create the input(s) needed for making the API call:
|
||||
# input_json = {
|
||||
# "tokenKey": row["tokenKey"],
|
||||
# "to": [row["to"]],
|
||||
# "subject": f"Reminder for Work - {datetime.datetime.now().strftime('%d/%m/%Y')}",
|
||||
# "body": [
|
||||
# {
|
||||
# "type": "html",
|
||||
# "part": {
|
||||
# "content": row["content"]
|
||||
# }
|
||||
# }
|
||||
# ]
|
||||
# }
|
||||
#
|
||||
# # We are now ready to make the API call:
|
||||
# exception = None
|
||||
# try:
|
||||
#
|
||||
# # Make the API call:
|
||||
# response = await http_client.post(
|
||||
# url = r"https://api.thecaoffice.com/converse/mail",
|
||||
# json = input_json
|
||||
# )
|
||||
#
|
||||
# # Get the log id from the response:
|
||||
# log_id = response.json()["logId"]
|
||||
# api_message = response.json()["message"]
|
||||
#
|
||||
# # If the API call failed:
|
||||
# response.raise_for_status()
|
||||
#
|
||||
# # If the API call goes wrong:
|
||||
# except Exception as e:
|
||||
# exception = e
|
||||
# printer(exception)
|
||||
#
|
||||
# # Send out an alert if needed:
|
||||
# if exception is not None:
|
||||
# await send_telegram(
|
||||
# message = (
|
||||
# f"*Reminders For Work (Mail)*\n\nException: `{exception}`\n\n"
|
||||
# f"Message: `{api_message}`\n\n"
|
||||
# f"Log Id: `{log_id}`"
|
||||
# ),
|
||||
# message_type = "error"
|
||||
# )
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user