欢迎访问 生活随笔!

生活随笔

当前位置: 首页 > 编程语言 > python >内容正文

python

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

发布时间:2024/9/15 python 65 豆豆
生活随笔 收集整理的这篇文章主要介绍了 python实现微信自动发信息_Python实现智慧-定期向微信女友发送消息,python,智给,定时,发消息... 小编觉得挺不错的,现在分享给大家,帮大家做个参考.

#author_='zhi';

#date: 2020/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 = "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()

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

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,智给,定时,发消息...的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。