利用python微信库itchat实现微信自动回复功能

yipeiwu_com5年前Python基础

前言

在论坛上看到了用Python登录微信并实现自动签到,才了解到一个新的Python库: itchat

利用Python 微信库itchat,可以实现自动回复等多种功能,好玩到根本停不下来啊,尤其是调戏调戏不懂计算机的,特别有成就感,哈哈!!

代码如下:

#coding=utf8
import requests
import itchat

KEY = '8edce3ce905a4c1dbb965e6b35c3834d'

def get_response(msg):
 apiUrl = 'http://www.tuling123.com/openapi/api'
 data = {
  'key' : KEY,
  'info' : msg,
  'userid' : 'wechat-robot',
 }
 try:
  r = requests.post(apiUrl, data=data).json()
  return r.get('text')
 except:
  return

@itchat.msg_register(itchat.content.TEXT)
def tuling_reply(msg):
 defaultReply = 'I received: ' + msg['Text']
 reply = get_response(msg['Text'])
 return reply or defaultReply

itchat.auto_login(hotReload=True)
itchat.run()

安装一下 itchat即可跑上面程序,实现与图灵机器人的交互。

总结

以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作能带来一定的帮助,如果有疑问大家可以留言交流,谢谢大家对【听图阁-专注于Python设计】的支持。

相关文章

TensorFlow数据输入的方法示例

TensorFlow数据输入的方法示例

读取数据(Reading data) TensorFlow输入数据的方式有四种: tf.data API:可以很容易的构建一个复杂的输入通道(pipeline)(首选数据输入方式...

Python安装官方whl包和tar.gz包的方法(推荐)

Windows环境:   安装whl包:pip install wheel    ->    pip install&n...

python list转dict示例分享

需求:['1:a','2:b','3:c'] 转换为 {'1′: 'a','3′: 'c','2′: ''} 复制代码 代码如下:a = {}b = ['1:a','2:b','3:c'...

python中wx将图标显示在右下角的脚本代码

复制代码 代码如下:import wx import imagesclass DemoTaskBarIcon(wx.TaskBarIcon):    TBM...

Python 读取图片文件为矩阵和保存矩阵为图片的方法

读取图片为矩阵 import matplotlib im = matplotlib.image.imread('0_0.jpg') 保存矩阵为图片 import numpy a...