Python下发送定时消息给微信好友

时间:2023-03-09 03:09:23
Python下发送定时消息给微信好友
 """
Description:时间可以改长一点 一分钟一个
Author:Nod
Date:
Record:
#---------------------------------v1-----------------------------------#
""" from __future__ import unicode_literals
from threading import Timer
from wxpy import *
import requests bot = Bot() # linux执行登陆请调用下面的这句
#bot = Bot(console_qr=2,cache_path="botoo.pkl")
#获取金山词霸每日一句,英文和翻译
def get_news():
url = "http://open.iciba.com/dsapi/"
r = requests.get(url)
content = r.json()['content']
note = r.json()['note']
return content, note def send_news():
try:
contents = get_news() # 你朋友的微信备注,请注意最好你的好友备注只有1个 my_friend = bot.friends().search(u'季学远')[0]
my_friend.send(contents[0])
my_friend.send(contents[1])
my_friend.send(u"Have a good one!")
# 每86400秒(1天),发送1次
t = Timer(86400, send_news)
t.start()
except: # 你的微信名称,不是微信帐号。 my_friend = bot.friends().search('季学远')[0]
my_friend.send(u"今天消息发送失败了") if __name__ == "__main__":
send_news()

pip3 install -i https://pypi.tuna.tsinghua.edu.cn/simple requests
pip3 install -i https://pypi.tuna.tsinghua.edu.cn/simple wxpy