30行python代码实现微信自动陪女盆友聊天

上班没时间回女朋友,30行py代码做个微信聊天机器人自动陪聊

视频地址https://www.bilibili.com/video/BV1sT4y1A7fH/

依赖库:

  1. requests(人性化的http请求库)
  2. itchat(网页微信接口库)

直接贴代码:

# -*- encoding: utf-8 -*-
"""
@File    :   chatbot.py
@Author  :   Joshua
@Contact :   [email protected]
"""
import itchat
import requests
from retry import retry


@retry(tries=3)
def robot_chat(text):
    url = "http://www.tuling123.com/robot-chat/robot/chat/759052/CUZW?geetest_challenge=&geetest_validate=&geetest_seccode="
    return requests.post(url, json={
        "perception": {"inputText": {"text": text}},
        "userInfo": {"userId": "demo"}
    }).json()['data']['results'][0]['values']['text']


@itchat.msg_register(itchat.content.TEXT, isFriendChat=True)
def auto_reply(msg):
    reply = "execuse me?"
    try:
        reply = robot_chat(msg.text)
    except:
        pass
    finally:
        print(f'[In] {msg.text} \t [Out] {reply}')
        return reply


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

使用方法:

  1. 粘贴代码至chatbot.py文件内
  2. 控制台执行pip install requestspip install itchat
  3. 然后继续执行python chatbot.py

友情提示:

GF来之不易,别整太多骚的,多点时间陪她吧~

下次一定:

觉得有用不妨来个赞~ 哈哈哈哈哈嗝

30行python代码实现微信自动陪女盆友聊天