Archive

Posts Tagged ‘notification’

How to send a notification to your Android phone from a Python script

Problem
I have a long-running script and when something important happens, I’d like to send a notification to my Android phone. This way I shouldn’t be close to my machine. How to do it?

Solution
I found a very simple solution for this that can be set up in 3 minutes. This service can be found at https://notify.run/ . First, install the necessary package:

$ pip install notify-run

Then, register a channel:

$ notify-run register

It’ll print a QR code to the screen. Scan it with your phone and it brings you to a page where you can accept the notifications to your phone. Then, you can send notifications with the following Python snippet:

from notify_run import Notify

notify = Notify()
notify.send('sent from my Python script')

As can be seen, you don’t need to specify the name of the channel. It’s because it’s stored in the file ~/.config/notify-run and the notify_run module picks it up automatically.

You can also send a message to the channel from the command line, thus you can integrate it in any application:

curl https://notify.run/<channel_id> -d "message goes here"

Links

Advertisements
Categories: python Tags: , , , ,