I'm trying to search a database for tomorrows date which then proceeds to an email function.
def send_email():
currentdate = time.strftime("%d/%m/%Y")
nextday = datetime.date.today() + datetime.timedelta(days=1)
tomorrow = str(nextday.strftime("%d %m %Y"))
with sqlite3.connect("school.db") as db:
cursor = db.cursor()
cursor.execute("SELECT DateIn FROM MusicLoan WHERE DateIn = ?",(tomorrow,))
row = cursor.fetchall()[0]
if str(row) == str(currentdate):
cursor.execute("SELECT StudentID FROM MusicLoan WHERE DateIn = ?", (currentdate))
ID = cursor.fetcone()[0]
cursor.execute("SELECT email FROM Student WHERE StudentID = ?",(ID))
email = cursor.fetchone()[0]
fromaddr = email
toaddr = "danielarif@blueyonder.co.uk"
msg = MIMEMultipart()
msg['From'] = fromaddr
msg['To'] = toaddr
msg['Subject'] = "Music Reminder"
body = "A reminder that your music is due in tomorrow"
msg.attach(MIMEText(body, 'plain'))
try:
server = smtplib.SMTP('smtp.gmail.com', 587)
server.ehlo()
server.set_debuglevel(1)
server.starttls()
server.ehlo()
server.login("danielarif123@gmail.com", "DanR0bJ0nes3")
text = msg.as_string()
server.sendmail(fromaddr, toaddr, text)
server.quit()
print("Email Sent Successfully")
send_email()
except smtplib.SMTPException:
print ("Error: unable to send email")
send_email()
my problem is is that it gets to the row = cursor.fetchall()[0] and then stops. How can I fix this
Aucun commentaire:
Enregistrer un commentaire