龙空技术网

假期苦短,我用Python!这有个自动回复拜年信息的小程序

大数据文摘 8629

前言:

现在你们对“python公众号自动回复代码”大体比较注意,各位老铁们都想要了解一些“python公众号自动回复代码”的相关资讯。那么小编同时在网摘上收集了一些关于“python公众号自动回复代码””的相关知识,希望兄弟们能喜欢,朋友们一起来了解一下吧!

大数据文摘出品

作者:李雷

有没有也被拜年短信(大部分是群发)搞得很焦虑?不回复似乎显得很没有礼貌,一一回复又累心劳神。

有没有既不浪费时间又能保持礼貌的办法呢?

人生苦短,我用Python!

知乎博主“余博伦”曾经在知乎上写过用12行python代码自动回复拜年信息的文章

我们在前辈的基础上,对代码进行了部分修改,还根据最近的节奏,加入了“加班”和“女朋友”触发彩蛋,让你能够自由增改自动回复的内容。

手把手告诉你如何过个解放双手的智能假期。

windows环境

1.pip安装

2.python安装

3.pycharm

4.微信

实现:自动拜年回复

1.Installing with get-pip.py

To install pip, securely download get-pip.py. [2]

PIP 官网首页

get-pip.py 下载地址

;file=get-pip.py

Then run the following:

在python 加入环境变量;CMD中 在get-pip.py的保存路径下执行

2.get-pip.py

python的路径 ,及 python下 pip的路径都配置进入

3.成功 pip

pip 安装 itchat 包的过程 01

pip 安装 itchat 包的过程 02

成功

代码

创建Python文件比如 newYear.py ,代码内容如下:

""" newYear.py test"""# coding: utf-8import itchat, refrom itchat.content import *import randomimport jsonimport codecs""" Constants"""#REPLY = {'default': '祝您猪年大吉'}REPLY = {'default': ''}try: with open("REPLY.json", 'r', encoding='utf-8') as load_f: json_str = load_f.read() print(json_str) if json_str: if json_str.startswith(u'\ufeff'): json_str = json_str.encode('utf8')[3:].decode('utf8') REPLY = json.loads(json_str)except Exception as e: print(e)print("replies:", REPLY)@itchat.msg_register([TEXT])def text_reply(msg): items = REPLY.items() defFlag = True for key, value in items: #print(key, ",", value) match = re.search(key, msg['Text']) if match: randomIdx = random.randint(0, len(REPLY[key])-1) itchat.send(REPLY[key][randomIdx], msg['FromUserName']) defFlag = False break if len(REPLY['default']) > 0 and defFlag: itchat.send(REPLY['default'], msg['FromUserName']) '''@itchat.msg_register([PICTURE, RECORDING, VIDEO, SHARING])def other_reply(msg): itchat.send((REPLY['default'], msg['FromUserName']))'''itchat.auto_login(enableCmdQR=True, hotReload=True)itchat.run()

运行 :

cmd 中

python newYear.py

屏幕出现二维码 微信扫码登陆,实现自动回复

扫码登录

微信登陆成功

自动回复效果

注意:

1、此回复是使用了微信网页端,即如果设置了自动回复,电脑端微信自动退出。

2、自动回复信息内容,都保存到了Json文件中,你可以用txt格式打开此文件夹,进行修改内容然后点击保存,就可以只有定制新年彩蛋。

文件都放在后台了,大数据文摘微信公众号回复“拜年”可以获得这两个文件,赶紧去试试吧,效果不错呦~

节省的时间就好好陪陪家人吧!最后,文摘菌祝大家新年快乐!

标签: #python公众号自动回复代码 #python 微信公众号回复