itchat模塊怎么在python中使用?針對(duì)這個(gè)問題,這篇文章詳細(xì)介紹了相對(duì)應(yīng)的分析和解答,希望可以幫助更多想解決這個(gè)問題的小伙伴找到更簡(jiǎn)單易行的方法。
import requests import json import itchat from threading import Timer global CITY_NAME CITY_NAME = "北京" headers = { 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.70 Safari/537.36' } def find_weather(): # 獲取天氣 weather_url = 'http://wthrcdn.etouch.cn/weather_mini?city={}'.format(CITY_NAME) city_response = requests.get(weather_url, headers=headers) return json.loads(city_response.text) def reform_fl(str_fl): new_str = str_fl.split("[")[2].split("]")[0] if new_str.startswith("<"): result = new_str.split("<")[1] else: result = new_str return result def send_news(str): itchat.auto_login() # 彈出一張圖片二維碼,掃描登錄網(wǎng)頁微信 person= itchat.search_friends(name='一只可愛的小奶貓') # 選擇給誰發(fā)送,name是他的備注 mylover = person[0]["UserName"] itchat.send(str, toUserName=mylover) Timer(86400, send_news).start() # 每隔86400秒發(fā)送一次,每天發(fā)一次 if __name__ == "__main__": weather_info = find_weather() forecast_weather = weather_info.get('data').get('forecast') ganmao = weather_info.get('data').get('ganmao') str_1 = '今天是:' + forecast_weather[0].get('date') + '\n' \ + '最高溫度:' + forecast_weather[0].get('high') + '\n' \ + '最低溫度:' + forecast_weather[0].get('low') + '\n' \ + '風(fēng)向:' + forecast_weather[0].get('fengxiang') + '\n' \ + '風(fēng)力:' + reform_fl(forecast_weather[0].get('fengli')) + '\n' \ + '天氣狀況:' + forecast_weather[0].get('type') + '\n' str_2 = "早安親愛滴:%s\n%s最近%s" % (str_1,CITY_NAME, ganmao) send_news(str_2)
關(guān)于itchat模塊怎么在python中使用問題的解答就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,如果你還有很多疑惑沒有解開,可以關(guān)注創(chuàng)新互聯(lián)成都網(wǎng)站設(shè)計(jì)公司行業(yè)資訊頻道了解更多相關(guān)知識(shí)。
另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)scvps.cn,海內(nèi)外云服務(wù)器15元起步,三天無理由+7*72小時(shí)售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國(guó)服務(wù)器、虛擬主機(jī)、免備案服務(wù)器”等云主機(jī)租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡(jiǎn)單易用、服務(wù)可用性高、性價(jià)比高”等特點(diǎn)與優(yōu)勢(shì),專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場(chǎng)景需求。
新聞標(biāo)題:itchat模塊怎么在python中使用-創(chuàng)新互聯(lián)
分享URL:http://vcdvsql.cn/article10/cscedo.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供動(dòng)態(tài)網(wǎng)站、虛擬主機(jī)、外貿(mào)網(wǎng)站建設(shè)、Google、域名注冊(cè)、搜索引擎優(yōu)化
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容