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

yipeiwu_com5年前Python基础

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

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

代码:

# -*- 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()

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持【听图阁-专注于Python设计】。

相关文章

python利用装饰器进行运算的实例分析

今天想用python的装饰器做一个运算,代码如下 >>> def mu(x): def _mu(*args,**kwargs): return x*x...

pandas DataFrame索引行列的实现

python版本: 3.6 pandas版本: 0.23.4 行索引 索引行有三种方法,分别是 loc iloc ix import pandas as pd impo...

Python3远程监控程序的实现方法

简述 一开始觉得这个很有趣,然后就想来做一个来玩一下 使用语言: Python3 使用工具:opencv视频监控 + socket数据传输技术 程序检验: 这里我考虑了一下,发现还是没有...

python统计多维数组的行数和列数实例

python菜鸟,每天都要进步一点点。 二维元组的例子: A = ((1, 1, 1), (1, 1, 1),(1, 1, 1),(0, 0, 0)) print len(A) #...

python常用函数与用法示例

本文实例讲述了python常用函数与用法。分享给大家供大家参考,具体如下: 自定义函数实例 # 定义一个函数 def printme( str ): "打印任何传入的字符串"...