rendering

Have you ever wanted to try sending notifications to your phone from a server or computer?

Have you ever been bothered by the anti-harassment mechanism of corporate email?

Now, we can use a simple and easy way to replace the corporate email!

To perform the following experiment, you need to be prepared

  • 1) Sign up and download IFTTT on your phone
  • 2) Python3

The following are the specific operation steps:

  1. First sign up for an IFTTT account (ifttt.com).

  2. Go to the my_applets page (ifttt.com/my_applets) and create an applet.

New the applet

Enter and click + this as shown.

Search webhooks.

Select Receive a Web Request. This trigger causes webHooks to trigger an event when they Receive an HTTP request.

Write the name of the trigger

Then click that.

Search notification.

Select Send a notification from the IFTTT app. This action causes IFTTT to issue a notification.

In the message format, {{EventName}} is the EventName set previously, while value1, value2, and value3 in Add ingredient are parameters in the HTTP request sent by the server.

You can set it to the following format:

Finish!

Ok, we are ready to write Python scripts!

3. Now in My Applets you should be able to see the webhooks you just created. Click on that and hit Learn More. Then go to webhooks down below. As shown in the figure.

my applets

Once in, click Documentation in the upper right corner.

Documents

Once inside, you can see your Key for the application. You can see that it is called by sending a POST or GET request to the following url:

https://maker.IFTTT.com/trigger/ your event_name/with/key/ your key

You can also take three arguments and place them in the body in JSON format, such as {“value1”: “This is a test “}, and the value1 in the final notification will be replaced by this value1.

Make a notification script, for example, create a new file called notice.py like this, text put the text that you want to send, you can put notice.py on your machine, you can put it on your server with some functionality. Remember to download IFTTT on your phone and log in first.

Open CMD(Windows)/Terminal(MacOS) to enter the directory and run:

python notice.py

The phone should receive a notification when it finishes running. If it does not, please check whether your system Settings allow IFTTT to notify.

import requests

def send\_notice(event\_name, key, text):
    url = "https://maker.ifttt.com/trigger/"+event\_name+"/with/key/"+key+""
    payload = "{\\n \\"value1\\": \ \""+text+"\ \"\\n}"
    headers = {
        'Content-Type': "application/json".'User-Agent': "PostmanRuntime / 7.15.0".'Accept': "/ \ \ * *".'Cache-Control': "no-cache".'Postman-Token': "a9477d0f-08ee-4960-b6f8-9fd85dc0d5cc,d376ec80-54e1-450a-8215-952ea91b01dd".'Host': "maker.ifttt.com".'accept-encoding': "gzip, deflate".'content-length': "63".'Connection': "keep-alive".'cache-control': "no-cache"
        }

    response = requests.request("POST", url, data=payload.encode('utf-8'), headers=headers)

    print(response.text)
Copy the code

Text = “603609.sh” Send_notice (‘ your event_name’, ‘your Key’, text)

The effect is as follows:

If you like, please follow the wechat public account: Python Practical Treasure book

There will be more useful Python tutorials in the future, so stay tuned to our website and public account!