Ten lines of code to implement python push notifications to mobile phones

When I was running deep learning recently, I often forgot that I was still training, so I ended up cutting back to see the results. Then I searched the Internet and finally found a pretty good application. You can use it without downloading anything, and the code is just About 10 lines (actually four lines can be)

Article directory

service preparation

pushplusThe service used here is

First enter the website to log in to get a personal token

image-20220407221414398

After the page is switched, scan the code on WeChat to follow the official account, and then enter some test strings in the try

image-20220407221532470

There is basically no delay, and you can receive push notifications on the WeChat public account

image-20220407221755707

In addition, there are other message templates json,text,markdownto choose from, and there are other channels. You can try it yourself. I just want to push the notification that the training is over, so it doesn't matter.

Although this website also has a vip service, but I read the introduction , the vip only limits the maximum number of messages sent per day and the format of the message content, and then there are fewer advertisements and priority push. If you just use it yourself, the normal version is completely enough. now,

code

import requests

def send_notice(content):
    token = "你的token"
    title = "训练成功"
    url = f"http://www.pushplus.plus/send?token={
      
      token}&title={
      
      title}&content={
      
      content}&template=html"
    response = requests.request("GET", url)
    print(response.text)

send_notice(f"训练正确率:55%\n测试正确率:96.5%")

After running the code, you can also receive the message push soon

image-20220407222109675

In subsequent use, you can use the following code directly

Suppose the file name of the above code issend.py

from send import send_notice

# 业务代码
# ......
# 消息推送
send("your content")

Guess you like

Origin blog.csdn.net/qq_46311811/article/details/124028451