天天减肥网,内容丰富有趣,生活中的好帮手!
天天减肥网 > python实现微信自动发信息_Python实现智慧-定期向微信女友发送消息 python 智给 定时 发消息...

python实现微信自动发信息_Python实现智慧-定期向微信女友发送消息 python 智给 定时 发消息...

时间:2023-06-07 13:48:57

相关推荐

python实现微信自动发信息_Python实现智慧-定期向微信女友发送消息 python 智给 定时 发消息...

#author_='zhi';

#date: /6/20 0020 13:34

from __future__ import unicode_literals

from threading import Timer

from wxpy import *

import requests

import random

bot = Bot()

# linux执行登陆请调用下面的这句

# bot = Bot(console_qr=2,cache_path="botoo.pkl")

def get_news():

"""获取金山词霸每日一句,英文和翻译"""

url = "/dsapi/"

r = requests.get(url)

content = r.json()['content']

note = r.json()['note']

return content, note

def send_news():

try:

contents = get_news()

# 你朋友的微信名称,不是备注,也不是微信帐号。

my_friend = bot.friends().search('小智')[0]

my_friend.send(contents[0])

my_friend.send(contents[1])

my_friend.send(u"晚安")

# 每86400秒(1天),发送1次

t = Timer(86400, send_news)

# 为了防止时间太固定,于是决定对其加上随机数

ran_int = random.randint(0, 100)

t = Timer(86400 + ran_int, send_news)

t.start()

except:

# 你的微信名称,不是微信帐号。

my_friend = bot.friends().search('小智哥')[0]

my_friend.send(u"今天消息发送失败了")

if __name__ == "__main__":

send_news()

如果觉得《python实现微信自动发信息_Python实现智慧-定期向微信女友发送消息 python 智给 定时 发消息...》对你有帮助,请点赞、收藏,并留下你的观点哦!

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。