Spaces:
Running
Running
import smtplib | |
from email.mime.multipart import MIMEMultipart | |
from email.mime.text import MIMEText | |
import time | |
import schedule | |
from functools import partial | |
import markdown | |
from datetime import date | |
DAY_TIME = 60 * 60 * 24 | |
import os | |
APP_PASSWORD = os.environ['APP_PASSWORD'] | |
def send_email(sender_email, app_password, recipient_email, subject, body): | |
# Create the email message | |
msg = MIMEMultipart() | |
msg['From'] = sender_email | |
msg['Subject'] = subject | |
msg['To'] = recipient_email | |
msg.attach(MIMEText(body, 'html')) | |
server = smtplib.SMTP_SSL('smtp.gmail.com', 8889) | |
try: | |
# Set up the SMTP server | |
server.starttls() # Secure the connection | |
server.login(sender_email, app_password) # Log in to your Gmail account | |
# Send the email | |
# for recipient_email in recipient_emails: | |
server.sendmail(sender_email, recipient_email, msg.as_string()) | |
# print("Email sent successfully!" + recipient_email) | |
except Exception as e: | |
print(f"Failed to send email: {e}") | |
finally: | |
server.quit() # Terminate the SMTP session | |
def sign_up_email(email, profile): | |
sender_email = "arxivcopilot@gmail.com" | |
app_password = APP_PASSWORD | |
recipient_email = email | |
# for recipient_email in email_pool.keys(): | |
email_input = {} | |
email_input['profile'] = profile | |
body = \ | |
(''' | |
# Welcome to Arxiv Copilot Monthly Updates! | |
## Hello, | |
Thank you for signing up for our monthly update service! We are thrilled to have you on board and look forward to providing you with the latest research topics, ideas, and papers tailored to your interests. | |
The updates will be sent on 1st of every month at 20:30 (EDT). | |
--- | |
### π **Your Profile Summary** | |
{profile} | |
--- | |
### π **What to Expect** | |
- Each month, you will receive an email with: | |
- **Trending Research Topics**: Stay updated on what's popular in your field. | |
- **Research Ideas**: Get inspired with new ideas tailored to your interests. | |
- **Recommended Papers**: Discover papers that match your research focus. | |
Thank you for choosing Arxiv Copilot. We are excited to support your research journey and keep you informed with the latest developments in your field. | |
Best regards, | |
**The Arxiv Copilot Team** | |
--- | |
*If you are unsatisfied with your profile, please edit it at Arxiv Copilot (https://huggingface.co/spaces/ulab-ai/ArxivCopilot) and sign up again!* | |
''').format_map(email_input) | |
body = markdown.markdown(body) | |
# body = MIMEText(body, "html") | |
subject = "ArxivCopilot Monthly" | |
send_email(sender_email, app_password, recipient_email, subject, body) | |
# Example usage | |
def send_to_users(agent): | |
if date.today().day != 1: | |
return | |
sender_email = "arxivcopilot@gmail.com" | |
app_password = APP_PASSWORD | |
for recipient_email in agent.email_pool.keys(): | |
profile_input = agent.email_pool[recipient_email] | |
topics, papers, ideas = agent.select_date("month", profile_input) | |
email_input = {} | |
email_input['profile'] = profile_input | |
email_input['topics'] = topics[0] | |
email_input['ideas'] = ideas[0] | |
paper_input = "" | |
for paper in papers.split(';\n'): | |
paper_input = paper_input + "- " + paper + ";\n" | |
email_input['papers'] = paper_input | |
body = \ | |
(''' | |
# Monthly Update from Arxiv Copilot | |
## Hello, | |
We are excited to share your personalized monthly update from Arxiv Copilot! Hereβs what we have for you this month: | |
--- | |
### π **Your Profile Summary** | |
{profile} | |
--- | |
### π₯ **Trending Research Topics** | |
{topics} | |
--- | |
### π‘ **Research Ideas for You** | |
{ideas} | |
--- | |
### π **Recommended Papers** | |
We have curated a list of papers you might find interesting: | |
{papers} | |
Thank you for being a part of Arxiv Copilot. We look forward to supporting your research journey. | |
Best regards, | |
**The Arxiv Copilot Team** | |
--- | |
*If you are unsatisfied with your profile, please edit it at Arxiv Copilot (https://huggingface.co/spaces/ulab-ai/ArxivCopilot) and sign up again!* | |
''').format_map(email_input) | |
body = markdown.markdown(body) | |
subject = "ArxivCopilot Monthly" | |
send_email(sender_email, app_password, recipient_email, subject, body) | |
print("sent to"+recipient_email) | |
def monthlyEmail(agent_ls): | |
agent = agent_ls[0] | |
job_with_para = partial(send_to_users, agent) | |
# schedule.every().minute.do(job_with_para) | |
# schedule.every().month.do(job_with_para).day.at("00:00") | |
schedule.every().day.at("20:30", "America/New_York").do(job_with_para) | |
while True: | |
schedule.run_pending() | |
time.sleep(59) | |