In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article will explain in detail how python realizes QQ to send New year's greetings regularly. The editor thinks it is very practical, so I share it with you as a reference. I hope you can get something after reading this article.
Effect picture:
Step 1: configure go-cqhttp
To put it simply, go-cqhttp is a QQ built by ourselves, which can complete functions such as sending and receiving messages, and automate the operation.
Official website address: go-cqhttp help Center
Https://docs.go-cqhttp.org/
Download interface:
We can choose according to our own situation. This is win10. Just choose go-cqhttp_windows_amd64.exe.
Create a new folder and put .exe in it. After running it, you will be prompted. Click OK, and a .bat will be generated. Run .bat again and you will see the following interface:
Select 0 press enter and follow the prompts to modify the .yml file
We need to modify the following areas:
Beginning of the document:
Change it to your own QQ account. In order to ensure security, it is recommended not to fill in the password and scan the code to log in.
End of document:
The # of the last two lines, replaced with two spaces (uncommented)
After saving, we run .bat again and follow the prompts to scan the code to log in. When you continue to jump out of the yellow text prompt, your go-cqhttp will be configured.
All subsequent python programs need to be run at the same time as go-cqhttp!
The second step is to get the friend list.
Using the interface provided by go-cqhttp, we can easily get the comments and QQ numbers of all our friends and save them as json files. The code is as follows:
Import requestsimport json if _ _ name__ ='_ _ main__': t = requests.get (url=' http://127.0.0.1:5700/get_friend_list') friends = t.json () # use the get_friend_list API to obtain the friend list with open (". / friends.json", 'friends, encoding='utf-8') as json_file: json.dump (friends, json_file, ensure_ascii=False) Indent=4) # Save the json file. Note that indent=4 allows json to be indented here.
After running it, in the same directory, we get friends.json, which looks like this when opened:
Remark is a comment for a friend, and we now use it as a slightly modified title for the message. (for example, Yi Weidong-> Weidong)
User_id is a friend's QQ number, which is used to send messages later.
If you do not want to send messages to some friends, you can delete the corresponding element (an element between "{},") in the file.
Step 3: send blessings!
Here, using the message sending interface of go-cqhttp, just run the following code (the same directory of .py should be put into friends.json)
Import requestsimport json if _ _ name__ = ='_ _ main__': with open ('. / friends.json', 'r' Encoding='utf8') as f: Flist = json.load (f) ['data'] for i in Flist: P = I [' remark'] # address Q = I ['user_id'] # QQ number requests.get (url=' http://127.0.0.1:5700/send_private_msg?user_id={0}&message={1} Happy New year Duck ~ wish you all the best in the new year!' .format (Q, p) requests.get (url=' http://127.0.0.1:5700/send_private_msg?user_id={0}&message=[CQ:face,id={1}][CQ:face,id={2}][CQ:face,id={3}]'.format(q,137,137,137))
Run the effect picture: (all friends in the json file will receive custom messages at the same time)
This is the end of this article on "how python realizes QQ to send New year greetings regularly". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, please share it out for more people to see.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.