脚本之家,脚本语言编程技术及教程分享平台!
分类导航

Python|VBS|Ruby|Lua|perl|VBA|Golang|PowerShell|Erlang|autoit|Dos|bat|

服务器之家 - 脚本之家 - Python - Python定时发送消息的脚本:每天跟你女朋友说晚安

Python定时发送消息的脚本:每天跟你女朋友说晚安

2021-04-10 00:40Mr_lee_long Python

今天小编就为大家分享一篇关于Python定时发送消息的脚本:每天跟你女朋友说晚安的文章,小编觉得内容挺不错的,现在分享给大家,具有很好的参考价值,需要的朋友一起跟随小编来看看吧

首先 你要有个女朋友

效果:

Python定时发送消息的脚本:每天跟你女朋友说晚安

需要安装几个包

  • pip install wxpy
  • pip install wechat_sender
  • pip install requests

代码如下:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
from __future__ import unicode_literals
from threading import Timer
from wxpy import *
from wechat_sender import Sender
import time,requests
bot = Bot(console_qr=2,cache_path='botoo.pk1') # 把consol_qr=2去掉,二维码是当做图片弹出来,否则则是以像素的方式打印出来,后面的参数是热登录,
def get_news():
  # 这里是把今日糍粑每日一句中拿过来的信息发送给你朋友
  url = "http://open.iciba.com/dsapi/"
  r = requests.get(url)
  contents = r.json()['content']
  translation = r.json()['translation']
  return contents,translation
def send_news():
  try:
    ufriend = bot.friends().search(u'Mr-Lee')[0] # 朋友微信昵称(不是备注,不是微信账号)
    ufriend.send(get_news()[0])
    ufriend.send(get_news()[1][5:])
    ufriend.send(u'晚安')
    t = Timer(86400,send_news) # 86400是间隔时间(一天)
    t.start()
  except:
    ufriend = bot.friends().search("L")[0] # 你的微信名称,不是微信号
    ufriend.send(u'消息发送失败')
if __name__ == '__main__':
  send_news()

总结

以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作具有一定的参考学习价值,谢谢大家对服务器之家的支持。如果你想了解更多相关内容请查看下面相关链接

原文链接:https://blog.csdn.net/weixin_41048363/article/details/79679987

延伸 · 阅读

精彩推荐