Push notification from python to android

I'm running some scripts and looking for an easy way to ping my phone once the script has finished running.

Doing some research on the web, I've seen ways of sending messages using Slack, Push bullet, twilio, email etc.

I am looking for recommendations for an easy way to send a ping/message from python to my phone.

Easy in the sense it dose not require considerable configuring of outside accounts or pay services.

3

5 Answers

U can try cmd: pip install telegram-send and just send a message to your Telegram bot. Create your telegram bot at BotFather, take a token from there, paste it to

cmd: telegram-send --configure 

Usage:

import telegram_send telegram_send.send(messages=["Hello world"]) 

I found this much better than any other push notification.

For more info: Link1 Link2

2

I have found a much easier way, but it doesn't works on Linux. Here is a link for more details.

First you have to install notify_run:

pip install notify_run 

Then you have to register:

notify-run register 

It will give you a QR code (on windows the QR code doesn't works) and a link, which will take you to a website, there press the "Subscribe on this device" (Maybe you will have to refresh the site)

Then use this code:

from notify_run import Notify notify = Notify() notify.send('any message you want') 
5

I've tried a Twilio, but it's complicated and I don't think it can send you messages for free (anymore). Telegram seems an easy solution. To extend to the answer of @Nick PV, here are the steps I, as a Telegram beginner, took:

1) Get a Telegram account (free) using your phone number

Web: Also download the Telegram Andriod. Of course, you want the notifications on your phone after all

2) Go into settings (web or app) and set a username

This is needed to obtain an id which your bot will use to send messages to

3) Send a message to RawDataBot to get your id

Just search for RawDataBot and send any message (hi will do). Take a note of your id.

4) Create your bot (which you'll command with HTTP requests)

Now search for BotFather and send the message /start. Help is displayed. Send the message /newbot and follow the instructions. Take a note of your token to access the HTTP API

5) Send the API request using Python

You could install and use telegram-send, but if you are like me and you prefer the generic library requests which will give you the experience to handle any HTTP API, this is how to do it:

import requests token = "token_from_step_4" url = f"" params = {"chat_id": "id_from_step_3", "text": "Hello World"} r = requests.get(url + "/sendMessage", params=params) 

Links:
Telegram bots:
API Docs sendMessage

1

In the end, the easiest way I found was using Slack. It takes one Python function (about 6 lines) and an Slack account.

More details can be found here on medium

1

I tried pushsafer and notify-run without success on my computer (Linux Mint 19.3 tricia)

On my computer, only Slack works properly. This post comes from this Youtube video where you will see the full process in Video.

What you need first is Slack application on your device (iOs, Android, ...) and create an Slack account (if not done)

Tuto :

  1. Create a workspace and an application (see details in this video. Sorry, I did not put the substeps here but I put this answer as a Community wiki in order to let you finish what I started :) )

  2. Install the python library pip3 install sandesh

    pip3 install sandesh

  3. Get your webhook =>

  4. Use this sample to send a message to Slack :

python code:

import sandesh sandesh.send("This is my test", webhook="<put here the https link of your webhook>") 

You can find the open source sandesh python module here in gitHub

1

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like