Use WechatPCAPI to realize simple version semi-automatic customized wechat New Year blessing group sending

Posted by lovesmith on Fri, 28 Jan 2022 16:46:46 +0100

The Chinese New Year is coming soon. In order to send sincere wishes to my friends, I used to send them one by one. It takes about 5-10 seconds to edit and send one. It takes at least an hour and a half for 1000 friends to send it continuously. It takes time and effort, and you can't watch the Spring Festival Gala.

So this year, I decided to find a time-saving and labor-saving mass distribution method, so I have the following content:

1, Demand

1. To: my friends

2. Mass content: customized messages, New Year greetings + [my name] + wishes + [name of friends] + New Year greetings

3. Operating system: windows10

4. Programs used: excel, notepad + +, pycharm, wechat computer version v2 7.1.82

5. Programming language: Python 3 seven

6. Core package: WechatPCAPI (website: https://github.com/jwpl190/WechatPCAPI ), WeChat PC version of the API interface, through WeChat can call WeChat to get friends, groups, official account list, and send messages and other functions. Thank the author for providing such an easy-to-use wechat interface call. For details, please visit the github address above.

7. Tool download:

(1) [provided by WechatPCAPI author] WechatPCAPI package + wechat computer version v2 7.1.82

Link: https://pan.baidu.com/s/1yADEwqht8hcTTjxpkW8DXw

Extraction code: rneo

(2) Pychar Ce (free): https://www.jetbrains.com/pycharm/download/download-thanks.html?code=PCC Click the link to pop up automatic download.

(3) excel and notepad + + will not be sent.

2, Specific steps

Principle: extract wechat friends' information, process the friends' wechat signals, blessings and other data into dictionary format, then import them into python project, and use WechatPCAPI to complete automatic transmission.

1. Install Python 3 7 (see: https://blog.csdn.net/weixin_43790276/article/details/89439352);

2. Unzip the wechatpcapi master file and transfer the wechatpcapi Copy the pyd file to python3.0 In the root directory of 7, wechatpcapi Copy the pyd file and lib folder to the root directory \ lib \ site packages (pyd file has not been used before, so the understanding of this part is a little vague. If any big man understands the call of pyd, please take me);

3. Install wechat computer version v2 7.1.82;

3. Open pycharm and new project, select the directory created by the project, and then find python3 in the Existing interpreter 7. If you don't click the right side to browse and find the corresponding directory:

4. In pycharm, create NewYear with file new Python file_ friendlist. py

Copy the following code:

# -*- coding: utf-8 -*-
from WechatPCAPI import WechatPCAPI
import
time,os # Callback function for receiving messages, which can be defined by yourself def on_message(message): print(message) def main(): # initialization wx example wx_inst = WechatPCAPI(on_message=on_message) # Starting wechat currently only supports wechat V2.7.1.82 wx_inst.start_wechat(block=True) # Wait until the login is successful. At this time, you need to manually scan the code to log in to wechat while not wx_inst.get_myself(): time.sleep(5) # Login succeeded print(wx_inst.get_myself()) # The following is for sending, which can be changed to anyone's wx_id
if __name__ == '__main__': main()

Run this code. If it works normally, the wechat login interface will pop up, scan the code to log in, and then list the information of all wechat friends in the log:

Where, wx_id_search is a friend wechat, wx_nickname is the nickname of your friend wechat, remark_name is a friend's note;

5. Data processing of friends and blessings:

The above is Wx_ The information of ID is copied into excel, and the data cleaning, friend address modification, blessing customization and other batch operations (omitted) are carried out by sorting and other methods. After being processed into the following format, it is saved as friendlist CSV and save it to the project directory;

6. Use notepad + + to open friendlist CSV. At the same time, create a new txt in this directory and name it friendlist txt, and change the code to UTF-8, put friendlist Copy all the text in CSV to txt file.

7. Adjust the format in txt in batch. The final format is as follows:

8. In pycharm, create NewYear with file new Python file_ send. py

Copy the following code:

# -*- coding: utf-8 -*-
from WechatPCAPI import WechatPCAPI
import time
import os


# Callback function for receiving messages, which can be defined by yourself
def on_message(message):
    print(message)


def main():
    # initialization wx example
    wx_inst = WechatPCAPI(on_message=on_message)

    # Starting wechat currently only supports wechat V2.7.1.82
    wx_inst.start_wechat(block=True)

    # Wait until the login is successful. At this time, you need to manually scan the code to log in to wechat
    while not wx_inst.get_myself():
        time.sleep(5)

    # Login succeeded
    print(wx_inst.get_myself())

    # [[key] open friendlist.txt,Load the group data from the file, read every row of data into dictionary format, then call the micro signal and blessing information in the dictionary to complete the transmission of information. sleep(1)Represents every 1 s Send a message, which can be modified by yourself.
# Be sure to pay attention wx_id_search and text and friendlist Txt, otherwise the call is wrong.
with open("friendlist.txt",encoding="utf-8") as f: for line in f: line_dic = eval(line) wx_inst.send_text(to_user=line_dic['wx_id_search'],msg=line_dic['text']) time.sleep(1) # Update all friends' information, and the data will be returned through the callback function above #wx_inst.update_frinds() if __name__ == '__main__': main()

9. Turn off wechat and run newyear_send.py, after scanning the code to log in to wechat, the blessing information is sent out one by one.

Note: both wechat nicknames and friends' notes may need to be modified when sending blessings. For example, if I want to send blessings to my mentor "Wang dahammer" (wechat notes), it is usually more appropriate to change it to Mr. Wang. Therefore, it is necessary to have a complex human processing process, but this method can save a lot of manpower compared with sending one by one manually.

This is the end of the simple customized blessing group sending applet. Because I am used to using excel for data processing, I do not use python, resulting in the most complex process of data processing. Welcome to optimize it together.