• python3.6_发送邮件


    #股票提醒系统
    
    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)
    
    
        
  • 相关阅读:
    Visual C++ 2012/2013的内存溢出检測工具
    MATLAB新手教程
    LCD开发之汉字显示
    支持向量机通俗导论(理解SVM的三层境地)
    类与类之间的简单传值
    hibernate官方新手教程 (转载)
    秒杀多线程第四篇 一个经典的多线程同步问题
    Java的位运算符具体解释实例——与(&amp;)、非(~)、或(|)、异或(^)
    mysql基础:mysql与C结合实例
    php实现字符串的排列(交换)(递归考虑所有情况)
  • 原文地址:https://www.cnblogs.com/xiuxiu123456/p/10879785.html
Copyright © 2020-2023  润新知