python实现微信定时每天和女友发送消息

作者:精神抖擞王大鹏 时间:2022-08-04 09:43:54 

但凡有些事情重复时,我就在想怎么可以用程序来自动化。这里想分享如何每天给女友定时微信发送”晚安“,如果只是晚安,就略显单调,于是爬取金山词霸每日一句,英文和翻译,借此设定定时器进行发送。

准备:


pip install wxpy
pip install requests

实现代码:


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('fairy')[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实现微信定时每天和女友发送消息

来源:https://blog.csdn.net/qq_29027865/article/details/81488654

标签:python,微信,定时发送
0
投稿

猜你喜欢

  • 微软:跑分速度不是IE8的开发重点

    2008-09-12 12:10:00
  • 实例:ASP与ACCESS链接

    2008-11-21 16:10:00
  • pytorch通过训练结果的复现设置随机种子

    2021-04-19 07:58:53
  • 微信小程序实现页面跳转传递参数(实体,对象)

    2023-08-09 06:30:20
  • python 随机森林算法及其优化详解

    2023-03-30 20:20:45
  • Web2.0时代的网页视觉设计

    2008-07-13 14:07:00
  • 详解CSS3中的属性选择符

    2008-04-24 14:30:00
  • Python Flask 转换器的使用详解

    2023-06-30 15:42:09
  • SQL Server中应当怎样得到自动编号字段

    2009-01-15 12:48:00
  • Python判断字符串与大小写转换

    2021-07-17 03:23:35
  • 玩转python爬虫之爬取糗事百科段子

    2022-09-23 12:20:52
  • Python中对字典的几个处理方法分享

    2021-03-13 05:48:57
  • 是时候不用考虑基于字体大小(em)的设计了

    2009-10-24 13:25:00
  • XMLHTTP 使用代理获取数据asp代码

    2010-03-22 14:40:00
  • Python + Requests + Unittest接口自动化测试实例分析

    2021-08-08 05:41:47
  • 巧用CSS滤镜做图案文字

    2011-04-29 14:06:00
  • PHP实现用户认证及管理完全源码

    2023-11-19 20:26:19
  • SQL SQL Server 2008中的新日期数据类型

    2009-03-10 15:01:00
  • 浅析SQL Server与Oracle数据库的区别

    2007-10-31 11:39:00
  • HTML5本地存储初探(一)

    2010-03-07 15:42:00
  • asp之家 网络编程 m.aspxhome.com