#股票提醒系统
import tushare
import time
import smtplib
from email.mime.text import MIMEText
def getrealtimequotes(share):
dataNow=tushare.get_realtime_quotes(share.code)
share.name=dataNow.loc[0][0]
share.price=float(dataNow.loc[0][3])
share.high=dataNow.loc[0][4]
share.low=dataNow.loc[0][5]
share.openToday=dataNow.loc[0][1]
share.pre_close=dataNow.loc[0][2]
share.volume=dataNow.loc[0][8]
share.amount=dataNow.loc[0][9]
share.timee=dataNow.loc[0][30]
share.describe='股票名'+share.name,'当前价格'+str(share.price)
return share
#发送邮件方法
def sendemail(subject,content):
msg_from="hexiuxiu1@126.com" #发送方
pwd='12344321a'#授权码
to='744827389@qq.com'
#subject='python邮件标题'
#content='python邮件正文'
#构造邮件
msg=MIMEText(content)
msg['Subject']=subject
msg['From']=msg_from
msg['To']=to
#发送邮件
try:
ss=smtplib.SMTP_SSL('smtp.126.com',465)
#ss=smtplib.SMTP('localhost')
ss.login(msg_from,pwd)
ss.sendmail(msg_from,to,msg.as_string())
print('发送成功')
except Exception as e:
print('发送失败')
raise e
class Share():
def __init__(self,code,buy,sale):
self.name=""
self.price=""
self.high=""
self.low=""
self.openToday=""
self.pre_close=""
self.volume=""
self.amount=""
self.timee=""
self.code=code
self.buy=buy
self.sale=sale
def main(sharelist):
for share in sharelist:
sss=getrealtimequotes(share)
print(share.describe)
if sss.price<=sss.buy:
sendemail('股票购买通知','股票降价了,赶紧买')
print('赶紧买!')
elif sss.price>=sss.sale:
sendemail('股票抛售通知','股票涨价了,赶紧卖')
print('可以卖了!')
else:
print('待定......')
while 1==1:
share1=Share('000591',3.3,3.4)
share2=Share('000591',3.3,3.4)
share3=Share('000591',3.3,3.4)
list1=[share1,share2,share3]
main(list1)
print('------------')
time.sleep(10)