通過python,定時發送微信消息


# -*- coding: UTF-8 -*-
import itchat
import time
import requests
#獲取金山詞霸每日一句
def get_new():
url="http://open.iciba.com/dsapi"
r=requests.get(url)
contents=r.json()['content']
note=r.json()['note']
    return contents,note
def send_news():
try:
itchat.auto_login(hotReload=True)
my_friend=itchat.search_friends(name=u'卡2')
FriendName=my_friend[0]["UserName"]
message1=get_new()[0]
#因為會出現進程報錯,所以我加上了 pass
pass
message2=get_new[1]
pass
message3=u"來自你的朋友"
pass
itchat.send(message1,toUserName=FriendName)
itchat.send(message2, toUserName=FriendName)
itchat.send(message3, toUserName=FriendName)
#每個1天發送消息
t=time(86400,send_news())
t.start()

except:
#如果上面其中一條消息沒有發送成功,就會發送本條消息
message4=u"你的朋友出bug了"
itchat.send(message4,toUserName=FriendName)

if __name__=="__main__":
send_news()


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM