Although the timing of the release of such an article is suspected of retaliation against society. But I think this kind of trick should be every student learning to program during the holidays.

Since the blessing can copy from the Internet a riff, perhaps even with copy extended/priest mass to TA your jokes, and then on the WeChat group assistant selection contacts, into a paste click send has successfully done all over the past year had ever loved to help encourage the relatives and friends in the same boat.

So why can’t I use a similar approach to someone who’s trying to target me with a mass message?

But I am not criticizing the blessing of this behavior, perfunctory is really a perfunctory point, how much is also a mind.

But I received the blessing is very embarrassed, if I do not return to appear I am not human, if I reply manually, it is obvious that I suffer a loss, may be a whole day of energy to consume in reply to blessing. And I don’t want to be the kind of person who sends wishes to my friends and family.

Is there a way to be polite and polite without wasting time?

Life is short. I use Python

For those of you who have studied programming for two years, all you need is 12 lines of Python code, and you can automatically reply to wechat messages. You can also automatically determine the type and content of messages and only reply to messages related to The New Year.

First make sure you have Python installed and Python’s package management tool PIP

  • Welcome to Python.org

  • Installation – pip 9.0.1 documentation


After that, only two more Python libraries need to be installed

pip install itchat pillow
Copy the code

And then I’m going to write these random lines of code

index.py

import itchat, time, re
from itchat.content import *

@itchat.msg_register([TEXT])
def text_reply(msg):
    match = re.search('年', msg['Text']).span()
    if match:
      itchat.send(('那我就祝你鸡年大吉吧'), msg['FromUserName'])

@itchat.msg_register([PICTURE, RECORDING, VIDEO, SHARING])
def other_reply(msg):
    itchat.send(('那我就祝你鸡年大吉吧'), msg['FromUserName'])

itchat.auto_login(enableCmdQR=True,hotReload=True)
itchat.run()
Copy the code

Then run it from the command line

python index.py
Copy the code

Scan the QR code using your wechat account (not the one below, but the one generated by yourself in the command line)

The following message is displayed after successful login

Then you’re done (this example is running in Win10+Python3.5.1)

Thank you for your support, update an advanced version, can automatically get friends’ remarks name, and randomly selected from the blessing API for customized reply, and will record the reply of friends, not because of repeated automatic reply.

The P.S. equests library needs to be installed again

import itchat, time, requests, random from itchat.content import * replied = [] @itchat.msg_register([TEXT]) def text_reply(msg): If 'year' in MSG ['Text'] and MSG ['FromUserName'] is not in: sendGreeting(msg) @itchat.msg_register([PICTURE, RECORDING, VIDEO, SHARING]) def other_reply(msg): if msg['FromUserName'] not in replyed: sendGreeting(msg) def sendGreeting(msg): UserName = MSG [' userName ']) itchat. Send ((friend[' userName ']+', '+getRandomGreeting()), msg['FromUserName']) replied.append(msg['FromUserName']) def getRandomGreeting(): The response = requests. Get (" http://www.xjihe.com/api/life/greetings?festival= & page = 10 "in the New Year, headers = {'apiKey':'sQS2ylErlfm9Ao2oNPqw6TqMYbJjbs4g'}) results = response.json()['result'] greeting = results[random.randrange(len(results))]['words'] return greeting itchat.auto_login(enableCmdQR=True,hotReload=True) itchat.run()Copy the code

Results the preview

The most important thing to be a friend is sincerity, the most important thing to be a man is kindness.

Of course, no matter how, blessing is blessing after all, how much the mind is also a little mind. The most important thing about Chinese New Year is to have fun

Finally, Yu Bolun is here to wish you a happy year of the Rooster ~ happy New Year ~

References:

  • Littlecodersh /ItChat from @Littlecoder
  • If it still does not work properly, please check the official documentation