I wrote a script that sends an email with the daily holiday. It works when run independently. I also wrote a script that sets a cronjob for it to run automatically, which correctly sets a cronjob, but the emails never send. The cronjob does work for other test scripts though. So both pieces work independently, just not for the email script. I checked the terminal mail and here's the error that arises which I don't know how to fix:
/anaconda3/lib/python3.7/getpass.py:91: GetPassWarning: Can not control echo on the terminal.
passwd = fallback_getpass(prompt, stream)
Warning: Password input may be echoed.
Password for <bggoldberg33@gmail.com>: Traceback (most recent call last):
File "/anaconda3/lib/python3.7/getpass.py", line 69, in unix_getpass
old = termios.tcgetattr(fd) # a copy to save
termios.error: (25, 'Inappropriate ioctl for device')
I'm fairly new to Python so can anyone help explain what this means and how to resolve it?
Python version 3.7.3 and using command line to run on MacOS 10.13.4
Here are the email and cron scripts for reference:
import yagmail
import pandas as pd
from datetime import datetime
# create variables
df = pd.read_excel('/Users/bgoldberg/PythonScripts/FunStuff/holidays.xlsx')
df['DateCheck'] = df['Date'] == datetime.today().strftime('%m/%d')
df = df.loc[df['DateCheck'] == True]
df.reset_index(inplace=True)
if len(df) == 1:
holiday1 = df.at[0, 'Holiday']
link1 = df.at[0, 'Link']
content = f'Happy {holiday1}! {link1}'
elif len(df) > 1:
holiday1 = df.at[0, 'Holiday']
link1 = df.at[0, 'Link']
holiday2 = df.at[1, 'Holiday']
link2 = df.at[1, 'Link']
content = f'Happy {holiday1}! {link1} \nHappy {holiday2}! {link2}'
else:
pass
weekday = datetime.today().strftime('%A')
# create email
receiver = 'bggoldberg33@gmail.com'
body = f'{content}'
yag = yagmail.SMTP('bggoldberg33@gmail.com')
yag.send(
to = receiver,
subject = 'Fun Daily Holidays',
contents = body
)
Cronjob:
from crontab import CronTab
my_cron = CronTab(user='bgoldberg')
job = my_cron.new(command='/anaconda3/bin/python3 /Users/bgoldberg/PythonScripts/FunStuff/emailTest.py')
job.minute.every(1)
my_cron.write()