30行python代码实现微信自动陪女盆友聊天
上班没时间回女朋友,30行py代码做个微信聊天机器人自动陪聊
视频地址: https://www.bilibili.com/video/BV1sT4y1A7fH/
依赖库:
- requests(人性化的http请求库)
- 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()
使用方法:
- 粘贴代码至
chatbot.py
文件内 - 控制台执行
pip install requests
和pip install itchat
- 然后继续执行
python chatbot.py
友情提示:
GF来之不易,别整太多骚的,多点时间陪她吧~
下次一定:
觉得有用不妨来个赞~ 哈哈哈哈哈嗝