import os
import time
import tushare as ts
import pandas as pd
import smtplib
from email.mime.text import MIMEText

def check(code, low, high):
global e
df = ts.get_realtime_quotes(code)
e = df[['code','name','price','time']]
p = df[u'price']
print (e)
if float(p[0]) > high:
user = 'xxxxxx@163.com' # 发件人,这里为163邮箱了
pwd = '*****' # 163邮箱的SMTP授权码
to = '******' # 可以设置多个收件人,英文逗号隔开,如:'***@qq.com, ***@163.com' # 1.邮件正文内容
msg = MIMEText('股票价格达到设定的价格') # 2.设置邮件主题、发件人、收件人
msg['Subject'] = '股票价格达到设定的价格!'
msg['From'] = user
msg['To'] = to # 3.发送邮件
s = smtplib.SMTP_SSL('smtp.163.com', 465) # 选择163邮箱服务,默认端口为465
s.login(user, pwd) # 登录163邮箱
s.send_message(msg) # 发送邮件
s.quit()
else :
return False

while True:
if check('603121',0,25.55):
exit()
time.sleep(5)