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 or float(p[0]) < low:
user = 'ahjx110@111.com' # 发件人,这里为163邮箱了
pwd = 'bbb' # 163邮箱的SMTP授权码
to = '18811111888@qq.com' # 可以设置多个收件人,英文逗号隔开,如:'***@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
stocks = ['600667','002288'];
while True:
for stock_code in stocks:
time.sleep(2)
if check(stock_code,11.10,12.30):
time.sleep(2)