欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

用Python定時發(fā)送天氣郵件

 更新時間:2022年02月07日 11:37:36   作者:See?you?again31  
大家好,本篇文章主要講的是用Python定時發(fā)送天氣郵件,感興趣的同學(xué)趕快來看一看吧,對你有幫助的話記得收藏一下

效果如圖 

一、獲取天氣

def getWeather1(city):
    try:
        appid = os.environ["TIANQI_APPID"]
        appsecret = os.environ["TIANQI_APPSEC"]
    except KeyError:
        appid = 'x'x'x'x'  #www.tianqiapi.com申請的appid,有免費(fèi) api
        appsecret = 'xxxx'  #在www.tiaSnqiapi.com申請的appsecret
    url = 'https://tianqiapi.com/api?version=v1&city={city}&appid={appid}&appsecret={appsecret}'.format(city=city,
                                                                                                        appid=appid,
                                                                                                        appsecret=appsecret)
    res = requests.get(url)
    if res.json().get("errcode", 0) > 0:
        print(res.json().get("errmsg"))
        exit(0)
    data = res.json()['data']
    weather = {
        'today': data[0],
        'tomorrow': data[1],
        'aftertomorrow': data[2]
    }
    today = weather['today']
    tomorrow = weather['tomorrow']
    aftertomorrow = weather['aftertomorrow']
 
    today_avg = (int(today['tem1'][:-1]) + int(today['tem2'][:-1])) / 2
    tomorrow_avg = (int(tomorrow['tem1'][:-1]) + int(tomorrow['tem2'][:-1])) / 2
    wdc ='紫外線指數(shù):'+today['index'][0]['level'] +'\n'+ \
           '穿衣指數(shù):'+today['index'][3]['desc']+'\n'
    wdc += 'tips:'+today['air_tips']
    today_w = '今天 {} {}/{} 風(fēng)力:{} 空氣指數(shù): {}/{} 日出日落: {}/{}'.format(today['wea'], today['tem1'], today['tem2'],today['win_speed'],today['air'],
                                                       today['air_level'], today['sunrise'], today['sunset'])
 
    tomorrow_w = '明天 {} {}/{} 風(fēng)力:{} 空氣指數(shù):{}/{} 日出日落: {}/{}'.format(tomorrow['wea'], tomorrow['tem1'], tomorrow['tem2'],tomorrow['win_speed'],tomorrow['air'],
                                                              tomorrow['air_level'], tomorrow['sunrise'],
                                                              tomorrow['sunset'])
 
    aftertomorrow_w = '后天 {} {}/{} 風(fēng)力:{} 空氣指數(shù):{}/{} 日出日落: {}/{}'.format(aftertomorrow['wea'], aftertomorrow['tem1'],
                                                                   aftertomorrow['tem2'],aftertomorrow['win_speed'],aftertomorrow['air'],
                                                                   aftertomorrow['air_level'], aftertomorrow['sunrise'],
                                                                   aftertomorrow['sunset'])
    todaytime = datetime.now()
    starttime = datetime.strptime('2020-08-21','%Y-%m-%d')
    days = (todaytime-starttime).days
    todaydate = str(todaytime.year) + '年' + str(todaytime.month) + '月' + str(todaytime.day) + '日'
    total = '早安!  親愛的xx,xxxxx~愿你每天開開心心!\n'+ \
            '今天是:'+todaydate+','+'是和xxx在一起的第'+str(days)+'天,mua~\n'+ \
            '近日天氣如下,xxx要注意保暖哦!\n'+ \
            today_w + '\n' + wdc +'\n'+ \
            tomorrow_w + '\n' + \
            aftertomorrow_w
    return total

二、獲取金山詞霸每日一句

def get_news():
    # 獲取金山詞霸的每日一句的英文和翻譯
    url = "http://open.iciba.com/dsapi/"
    r = requests.get(url)
    content = r.json()['content']
    note = r.json()['note']
    news = content + '\n' + \
            note
    return str(news)

三、獲取Sweet word

def getSweetWord():
    url = 'https://chp.shadiao.app/api.php'
    res = requests.get(url)
    return res.text

四、發(fā)送郵件

def sendemail(toaddr='', message=''):
    fromaddr = 'xxxxx@qq.com'  # 你的郵箱
    password = 'xxxxxfslfbfgg'  # 你的密碼,注意不是qq密碼
    smtp_server = 'smtp.qq.com'  # smtp地址
    msg = MIMEText(message, 'plain', 'utf-8')
    msg['From'] = _format_addr('xxx <%s>' % fromaddr)
    msg['To'] = _format_addr('xxx <%s>' % toaddr)
    todaytime = datetime.now()
    starttime = datetime.strptime('2020-08-21', '%Y-%m-%d')
    days = (todaytime - starttime).days
    emailtitle= '愛你的第'+str(days)+'天'
    msg['Subject'] = Header(emailtitle, 'utf-8').encode()
    server = smtplib.SMTP_SSL(smtp_server, 465)
    server.set_debuglevel(1)
    server.login(fromaddr, password)
    server.sendmail(fromaddr, [toaddr], msg.as_string())
    server.quit()
    return

五、組織信息,并發(fā)送

def dailymorning():
 
    message = getWeather1('xxx') + '\n' + \
              get_news() + '\n' + \
              getSweetWord() + '\n' + \
                '來自最愛你xxx'
 
    receivers = [['xxxx@qq.com'], ['xxxxxx@qq.com']]
    for i in range(len(receivers)):
        dailyemail.sendemail(toaddr=receivers[i], message=message)
        print('send receiver[{}] success'.format(receivers[i]))

六、win10系統(tǒng)設(shè)置定時啟動程序。

到此這篇關(guān)于用Python定時發(fā)送天氣郵件的文章就介紹到這了,更多相關(guān)Python發(fā)送天氣郵件內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • 使用python處理題庫表格并轉(zhuǎn)化為word形式的實(shí)現(xiàn)

    使用python處理題庫表格并轉(zhuǎn)化為word形式的實(shí)現(xiàn)

    這篇文章主要介紹了使用python處理題庫表格并轉(zhuǎn)化為word形式的實(shí)現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2020-04-04
  • python并發(fā)和異步編程實(shí)例

    python并發(fā)和異步編程實(shí)例

    這篇文章主要為大家詳細(xì)介紹了python并發(fā)和異步編程實(shí)例,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2018-11-11
  • Python3.10的一些新特性原理分析

    Python3.10的一些新特性原理分析

    由于采用了新的發(fā)行計(jì)劃:PEP 602 -- Annual Release Cycle for Python,我們可以看到更短的開發(fā)窗口,我們有望在 2021 年 10 月使用今天分享的這些新特性
    2021-09-09
  • 詳解python的網(wǎng)絡(luò)編程基礎(chǔ)

    詳解python的網(wǎng)絡(luò)編程基礎(chǔ)

    這篇文章主要為大家介紹了python網(wǎng)絡(luò)編程的基礎(chǔ),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下,希望能夠給你帶來幫助
    2022-01-01
  • python神經(jīng)網(wǎng)絡(luò)MobileNetV2模型的復(fù)現(xiàn)詳解

    python神經(jīng)網(wǎng)絡(luò)MobileNetV2模型的復(fù)現(xiàn)詳解

    這篇文章主要為大家介紹了python神經(jīng)網(wǎng)絡(luò)MobileNetV2模型的復(fù)現(xiàn)詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2022-05-05
  • Qt5.14 與 OpenCV4.5 教程之圖片增強(qiáng)效果

    Qt5.14 與 OpenCV4.5 教程之圖片增強(qiáng)效果

    這篇文章主要介紹了Qt5.14 與 OpenCV4.5 教程之圖片增強(qiáng)效果的實(shí)現(xiàn),本文通過圖文并茂的形式給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友參考下吧
    2021-11-11
  • python實(shí)現(xiàn) 獲取b站主播直播間 粉絲牌信息的方法

    python實(shí)現(xiàn) 獲取b站主播直播間 粉絲牌信息的方法

    這篇文章主要介紹了python實(shí)現(xiàn) 獲取b站主播直播間粉絲牌信息 ,用于實(shí)現(xiàn)通過牌子逆向查主播信息這個功能,本文結(jié)合實(shí)例代碼給大家介紹的非常詳細(xì),需要的朋友可以參考下
    2023-02-02
  • 在python plt圖表中文字大小調(diào)節(jié)的方法

    在python plt圖表中文字大小調(diào)節(jié)的方法

    今天小編就為大家分享一篇在python plt圖表中文字大小調(diào)節(jié)的方法,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2019-07-07
  • opencv python簡易文檔之圖像處理算法

    opencv python簡易文檔之圖像處理算法

    OpenCV是一個開源庫,包含了許多計(jì)算機(jī)視覺算法,它在計(jì)算機(jī)視覺和圖像處理中起著重要作用,用于實(shí)時操作,其效率足以滿足工業(yè)上的要求,這篇文章主要給大家介紹了關(guān)于opencv python簡易文檔之圖像處理算法的相關(guān)資料,需要的朋友可以參考下
    2021-08-08
  • Python中用memcached來減少數(shù)據(jù)庫查詢次數(shù)的教程

    Python中用memcached來減少數(shù)據(jù)庫查詢次數(shù)的教程

    這篇文章主要介紹了Python中用memcached來減少數(shù)據(jù)庫查詢次數(shù)的教程,memcached是一種分布式的內(nèi)存緩存工具,使用后可以減少對硬盤的I/O次數(shù),需要的朋友可以參考下
    2015-04-04

最新評論