python實現(xiàn)的自動發(fā)送消息功能詳解
本文實例講述了python實現(xiàn)的自動發(fā)送消息功能。分享給大家供大家參考,具體如下:
一個簡單的腳本
#-*- coding:utf-8 -*- from __future__ import unicode_literals from threading import Timer import itchat import requests # 抓取金山毒霸每日一句,英文和翻譯 def get_news(): url = "http://open.iciba.com/dsapi/" r = requests.get(url) content = r.json()['content'] translation = r.json()['translation'] return content, translation def send_news(): try: # 把抓取的數(shù)據(jù)傳參 contents = get_news() # 登陸微信賬戶,掃碼登陸 itchat.auto_login(hotReload=True) # 查找你微信號上想要發(fā)送人的名稱 my_friend = itchat.search_friends(name=u'loli') # 發(fā)送消息 itchat.send(contents[0], toUserName=my_friend) itchat.send(contents[1], toUserName=my_friend) itchat.send(u"I love you", toUserName=my_friend) # 一天循環(huán)發(fā)送一次 t = Timer(86400, send_news) t.start() except: my_friend = itchat.search_friends(name=u'loli') itchat.send(u"今天消息發(fā)送失敗了", toUserName=my_friend) if __name__ == '__main__': send_news()
需要安裝的包:
pip install requests pip install itchat
這里以抓取金山毒霸句子為例。
效果圖:
參考資料:
https://zhuanlan.zhihu.com/p/36398109
http://www.dbjr.com.cn/article/136992.htm
更多關(guān)于Python相關(guān)內(nèi)容可查看本站專題:《Python Socket編程技巧總結(jié)》、《Python數(shù)據(jù)結(jié)構(gòu)與算法教程》、《Python函數(shù)使用技巧總結(jié)》、《Python字符串操作技巧匯總》、《Python入門與進階經(jīng)典教程》及《Python文件與目錄操作技巧匯總》
希望本文所述對大家Python程序設(shè)計有所幫助。
相關(guān)文章
matplotlib設(shè)置顏色、標記、線條,讓你的圖像更加豐富(推薦)
這篇文章主要介紹了matplotlib設(shè)置顏色、標記、線條,讓你的圖像更加豐富,本文通過實例圖文相結(jié)合給大家介紹的非常詳細,對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下2020-09-09把Anaconda中的環(huán)境導(dǎo)入到Pycharm里面的方法步驟
這篇文章主要介紹了把Anaconda中的環(huán)境導(dǎo)入到Pycharm里面的方法步驟,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-10-10Pytorch搭建YoloV5目標檢測平臺實現(xiàn)過程
這篇文章主要為大家介紹了Pytorch搭建YoloV5目標檢測平臺實現(xiàn)過程,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪2022-04-04將pandas.dataframe的數(shù)據(jù)寫入到文件中的方法
今天小編就為大家分享一篇將pandas.dataframe的數(shù)據(jù)寫入到文件中的方法,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2018-12-12面向?qū)ο髮W(xué)習(xí)之pygame坦克大戰(zhàn)
這篇文章主要為大家詳細介紹了面向?qū)ο髮W(xué)習(xí)之pygame坦克大戰(zhàn),具有一定的參考價值,感興趣的小伙伴們可以參考一下2019-09-09