zoukankan      html  css  js  c++  java
  • 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)
    
    
        
  • 相关阅读:
    Leetcode:Convert Sorted List to Binary Search Tree
    Leetcode:Unique Binary Search Trees & Unique Binary Search Trees II
    Leetcode::Longest Common Prefix && Search for a Range
    Leetcode::Flatten Binary Tree to Linked List
    Leetcode::JumpGame
    leetcode power(x,n)
    Leetcode Letter Combinations of a Phone Number
    leetcode Reverse Nodes in k-Group
    leetcode Merge k Sorted Lists
    word ladder
  • 原文地址:https://www.cnblogs.com/xiuxiu123456/p/10879785.html
Copyright © 2011-2022 走看看