In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly explains "how Python automates APP to send WeChat group messages". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn "how Python automates APP to send WeChat group messages".
1. Preface
But for many people, writing an App first requires some mobile development experience, and secondly, it needs to write barrier-free service applications, so it seems difficult.
two。 Reptiles and services
For the convenience of demonstration, Baidu Hot search is used as the data source of the Morning Post.
Use Requests + BeautifulSoup to crawl the 15 hottest data according to the heat
Import requestsfrom bs4 import BeautifulSoupdef baidu_top_tipic (): "Baidu Hot search"requests_page = requests.get ('http://top.baidu.com/buzz?b=1&c=513&fr=topbuzz_b42_c513') soup = BeautifulSoup (requests_page.text," lxml ") # query soup_text = soup.find_all (" div ", class_='c-single-text-ellipsis', text=True) top_list = [] for index Text in enumerate (soup_text): top_list.append ((str (index + 1) + "," + text.string.strip () # take the 15 hottest data return'\ n'.join (top_list [: 15])
Then, use FastAPI to write an API to obtain the morning news, and deploy it to the cloud server (here take CentOS as an example)
Import uvicornfrom fastapi import FastAPIfrom every_news import * # pip3 install uvicorn# pip3 install fastapi# instantiation app= FastAPI () # Daily News @ app.get ("/ news") async def rsc_api (): msg = get_news () return {"code": 200, "msg": msg} if _ _ name__ = ='_ main__': uvicorn.run (app='news_api:app', host= "0.0.0.0" Port=6789, reload=True, debug=True)
Finally, run the following command to make the service run in the background
# Command line background runs # log directory: / news_api.lognohup python3 / xag/news_api.py > / news_api.log 2 > & 1 & 3. Send group chat automatically
Write AutoJS script in VS Code
First, define a way to send messages to a group chat
PS: click operation using click () coordinates is only applicable to Android 7.0 +
/ / call API to get news data var url = "http://host:6789/news";// send group chat name var group_name =" group chat name " / / send a message to WeChat group function send_wx_msg (group_name, send_msg) {/ / if hibernating, wake up the device / / Note: to ensure low power consumption, set sleep (no operation for 10 seconds) device.wakeUpIfNeeded () / / Open Wechat app.launch ("com.tencent.mm") Text ("Wechat"). WaitFor () / / Click to enter the chat interface var chat_element_bounds = text (group_name). FindOne (). Bounds (); / / supports Android7.0+ click (chat_element_bounds.centerX (), chat_element_bounds.centerY ()) Sleep (3000) id ("auj"). ClassName ("EditText"). FindOne (). SetText (send_msg) sleep (3000) / / send the message text ("send"). Click () log ("sent successfully!") / / return to the mobile desktop back (); home ()
Then, start a new thread in the main thread, call the API interface, get the data and send it out
/ / Thread threads.start (function () {/ / get news http.get (url, {}, function (res, err) {/ / error if (err) {log ("Sorry! failed to get news today.") Return;} log ("Today's news is a success!") Let html = res.body.string (); let msg = JSON.parse (html) .msg; send_wx_msg (group_name, msg)});})
Next, use VS Code to import the source code into the mobile device
Finally, select the source file-right-click-more-scheduled tasks, and set scheduled tasks.
At this point, I believe you have a deeper understanding of "how Python automates APP to send WeChat group messages". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
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.