【发布时间】:2015-04-27 11:51:24
【问题描述】:
我正在尝试在数据库中搜索明天的日期,然后转到电子邮件功能。
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(tomorrow):
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()
我的问题是它到达 row = cursor.fetchall()[0] 然后停止。 我该如何解决这个问题
【问题讨论】:
标签: python sql database sqlite datetime