首页 技术 正文
技术 2022年11月21日
0 收藏 771 点赞 4,428 浏览 887 个字

但凡一件事,稍微有些重复。我就考虑怎么样用程序来实现它。

这里给各位程序员朋友分享如何每天给朋友定时微信发送”晚安“,故事,新闻,等等··· ···
最好运行在服务器上,这样后台挂起来更方便。

准备:

微信号

pip install wxpy

pip install requests

代码如下:

# 不要抄下源码就运行,你需要改动几个地方from __future__ import unicode_literals
from threading import Timer
from wxpy import *
import requestsbot = 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, notedef send_news():
try:
content,note = get_news() # 你朋友的微信名称,不是备注,也不是微信帐号。
my_friend = bot.friends().search(u'小明')[0]
my_friend.send(content)
my_friend.send(note)
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()

最终效果是这样的:

python实战===教你用微信每天给女朋友说晚安

python实战===教你用微信每天给女朋友说晚安

总结:

代码让生活更美好!


顺便提一下:

如果你执行代码有任何问题,你可以在这里找到我

QQ群:810306356

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:8,990
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,504
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,348
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,133
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,765
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,843