您的位置:首页 > 脚本大全 > > 正文

python发送微信消息脚本(python实现微信每日一句自动发送给喜欢的人)

更多 时间:2021-10-14 00:29:33 类别:脚本大全 浏览量:1775

python发送微信消息脚本

python实现微信每日一句自动发送给喜欢的人

本文实例为大家分享了python实现微信每日一句自动发送的具体代码,供大家参考,具体内容如下

参考了一篇博客:教你使用python实现微信每天给女朋友说晚安

代码:

  • ?
  • 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
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • # -*- coding: utf-8 -*-
  • '''
  • 这是一个用来测试微信自动发送消息的demo
  • 恩,主要就是用到了一个微信库--wxpy
  • 安装很简单 pip install wxpy
  • 下面就开始吧
  • 主要就两个函数
  • 1、getnews();用以获取信息
  • 2、sendnews();用以发送信息
  •  
  • 我这里发送消息用的是for循环本意是群发,但是!但是!但是!程序发的太快会被微信禁掉,大概40个人左右就会被禁,以后可以试试sleep一下。
  •  
  • 另外vscode中自定义python编译器:
  • ctrl+shift+p, 选择 python: select interpreter
  • '''
  •  
  •  
  • from __future__ import unicode_literals
  • from wxpy import *
  • import requests
  • from threading import timer
  •  
  • itchat = bot(console_qr=2,cache_path="botoo.pkl")
  • def getnews():
  •   url = "http://open.iciba.com/dsapi/"
  •   r = requests.get(url)
  •   content = r.json()['content']
  •   note = r.json()['note']
  •   return content, note
  •  
  • def sendnews():
  •   try:
  •     #这里是备注
  •     friend = itchat.friends().search(name = u'xxx')
  •  
  •     content = getnews()
  •     print(content)
  •     message1 = str(content[0])
  •     message2 = str(content[1])
  •     message3 = "xxx"
  •     print(friend)
  •  
  •     for index,item in enumerate(friend):
  •  
  •  
  •       print("发送给 "+str(item)+" ing,index="+str(index))
  •       item.send(message1)
  •       item.send(message2)
  •       item.send(message3)
  •  
  •     t = timer(86400,sendnews)
  •     t.start()
  •   except:
  •     errormessage = "xxx"
  •     for index,item in enumerate(friend):
  •       item.send(errormessage)
  •  
  •  
  • if __name__ == "__main__":
  •   sendnews()
  • 以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持开心学习网。

    原文链接:https://blog.csdn.net/u011554976/article/details/80604004

    您可能感兴趣