Spaces:
Sleeping
Sleeping
Richard Fan
commited on
Commit
·
9910188
1
Parent(s):
e68fb0a
src/action.py changes
Browse files- src/action.py +17 -17
src/action.py
CHANGED
|
@@ -120,23 +120,23 @@ if __name__ == "__main__":
|
|
| 120 |
to_email = os.environ.get("TO_EMAIL")
|
| 121 |
threshold = config["threshold"]
|
| 122 |
interest = config["interest"]
|
|
|
|
| 123 |
with open("digest.html", "w") as f:
|
| 124 |
-
body = generate_body(topic, categories, interest, threshold)
|
| 125 |
f.write(body)
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
else:
|
| 140 |
-
print("Send test email: Failure ({response.status_code}, {response.text})")
|
| 141 |
else:
|
| 142 |
-
print("
|
|
|
|
|
|
|
|
|
| 120 |
to_email = os.environ.get("TO_EMAIL")
|
| 121 |
threshold = config["threshold"]
|
| 122 |
interest = config["interest"]
|
| 123 |
+
body = generate_body(topic, categories, interest, threshold)
|
| 124 |
with open("digest.html", "w") as f:
|
|
|
|
| 125 |
f.write(body)
|
| 126 |
+
if os.environ.get('SENDGRID_API_KEY', None):
|
| 127 |
+
sg = SendGridAPIClient(api_key=os.environ.get('SENDGRID_API_KEY'))
|
| 128 |
+
from_email = Email(from_email) # Change to your verified sender
|
| 129 |
+
to_email = To(to_email)
|
| 130 |
+
subject = date.today().strftime("Personalized arXiv Digest, %d %b %Y")
|
| 131 |
+
content = Content("text/html", body)
|
| 132 |
+
mail = Mail(from_email, to_email, subject, content)
|
| 133 |
+
mail_json = mail.get()
|
| 134 |
+
|
| 135 |
+
# Send an HTTP POST request to /mail/send
|
| 136 |
+
response = sg.client.mail.send.post(request_body=mail_json)
|
| 137 |
+
if response.status_code >= 200 and response.status_code <= 300:
|
| 138 |
+
print("Send test email: Success!")
|
|
|
|
|
|
|
| 139 |
else:
|
| 140 |
+
print("Send test email: Failure ({response.status_code}, {response.text})")
|
| 141 |
+
else:
|
| 142 |
+
print("No sendgrid api key found. Skipping email")
|