1
Fork 0
mirror of https://github.com/pds-nest/nest.git synced 2024-11-25 06:24:19 +00:00

🐛 Fix datetime import

This commit is contained in:
Steffo 2021-05-30 17:23:29 +02:00
parent 73dfbbc403
commit 27485e8e7e
Signed by: steffo
GPG key ID: 6965406171929D01

View file

@ -4,7 +4,6 @@ from .authentication import authenticate
import smtplib import smtplib
import os import os
import tweepy as tw import tweepy as tw
import datetime
MESSAGE = "{alert_name}: la soglia di allerta è stata superata alle {now}!" MESSAGE = "{alert_name}: la soglia di allerta è stata superata alle {now}!"
@ -55,7 +54,7 @@ def send_notification_email(alert):
smtpObj.login(os.environ["SMTP_USERNAME"], os.environ["SMTP_PASSWORD"]) smtpObj.login(os.environ["SMTP_USERNAME"], os.environ["SMTP_PASSWORD"])
smtpObj.sendmail(os.environ["SMTP_FROM_EMAIL"], smtpObj.sendmail(os.environ["SMTP_FROM_EMAIL"],
alert.repository.owner.email, alert.repository.owner.email,
MESSAGE.format(alert_name=alert.name, now=datetime.datetime.now().isoformat())) MESSAGE.format(alert_name=alert.name, now=datetime.now().isoformat()))
print("Successfully sent email") print("Successfully sent email")
except smtplib.SMTPException: except smtplib.SMTPException:
print("Error: unable to send email") print("Error: unable to send email")
@ -69,7 +68,7 @@ def send_notification_tweet(alert):
conditions_string = conditions_string[:-1] conditions_string = conditions_string[:-1]
print(conditions_string) print(conditions_string)
try: try:
api.update_status(MESSAGE.format(alert_name=alert.name, now=datetime.datetime.now().isoformat())) api.update_status(MESSAGE.format(alert_name=alert.name, now=datetime.now().isoformat()))
except tw.errors.Forbidden: except tw.errors.Forbidden:
print("Il tweet e' gia' stato pubblicato") print("Il tweet e' gia' stato pubblicato")