Package: python-pushover-open-client
python-pushover-open-clientCommand line app and framework for receiving and processing Pushover push notifications in real time.FeaturesReceive notifications real time via Pushover websocket server.Execute python funcions via commands received by notification, passing arguments as*args.Execute shell commands, passing arguments.Execute python functions to all received notifications (eg.,. you can usePopento send all notifications tonotify-send.)Can be run as a system service, enabling your scripts from boot time.It is being developed with facilities to make it easy subclassing.Installingpip install python-pushover-open-clientPython minimum version 3.10is needed.(because of the `|` union
annotations.)Setting UpThe script expects a file at the home directory named~/.pushover-open-client-creds.json. The file should be a JSON file with
account’semailandpassword, this way:file:~/.pushover-open-client-creds.json{
  "email": "USERS@EMAIL.ETC",
  "password": "M4HSUP3RBPASS"
}Given the above, by logging and getting an auth secret, a new device will be
created wielding it’s device_id, and that file will be updated containing all
these four values.UsingCommand lineOur command linepushover-open-clientstill needs more functions,
but we already have one.His whole interface is here.pushover-open-clientjsonThis command outputs new received notifications and can be used to pipe for
your own scripts to be processed.ProgramaticallyHere is an example script of how using decorators to use the lib. More examples
will be added soon, as there are more decorators/functions to be used.file:notify.py#!/usr/bin/env pythonfromsubprocessimportPopenfrompython_pushover_open_clientimportregister_commandfrompython_pushover_open_clientimportregister_parserfrompython_pushover_open_clientimportPushoverOpenClientRealTime# Let's use a decorator to registrate a command function; it will be executed# when a message with `mycmd_rawdata` as the first word is received. All# the arguments, *ie.*, all the words in the notification, including# `mycmd_rawdata` will be passed to ``*args``:@register_commanddefmycmd_rawdata(*args,raw_data=None):print("RAW DATA IS:",raw_data)# this decorator register a parser which is executed for each new# notification received; here we have two examples:@register_parserdefmy_notify_send_parser(raw_data=None):args_str="notify-send\"{message}\"".format(message=raw_data["message"])Popen(args=args_str,shell=True)@register_parserdefmy_print_parser(raw_data=None):print("MESSAGE RECEIVED:",raw_data)# this instantiates the Pushover websocket class and runs it:client=PushoverOpenClientRealTime()client.run_forever()You can save the script above to a file (eg.~/notify.py), then make it
executable and run, after you haveinstalled the packageandentered your Pushover credentials:chmod+xnotify.py./notify.pyThen while it is running,  try to send a notification to the device (or all
the devices) viaPushover websiteor other notification sending app.Full featured Pushover client using this libSend notification to desktop (if you usenotify-send) and show the
notification on the terminal executing it. Only lacks the Pushover App icon.You can even create a systemd service to always receive the notifications on
desktop automatically. (In this case, you can delete the terminal printing
lines.)file:python-client.py#!/usr/bin/env pythonfromsubprocessimportPopenfrompython_pushover_open_clientimportregister_parserfrompython_pushover_open_clientimportPushoverOpenClientRealTimePERMANENT_NOTIFICATION=True# should notifications stay until clicked?# shows notifications on Desktop using `notify-send`@register_parserdefmy_notify_send_parser(raw_data=None):"""Executes notify-send to notify for new notifications."""message=raw_data['message']title=raw_data['title']ifraw_data['title']else'_'is_permanent=["-t","0"]ifPERMANENT_NOTIFICATIONelse[]args=['notify-send',*is_permanent,title,message]Popen(args=args)# prints to the terminal@register_parserdefmy_terminal_output_parser(raw_data=None):"""Outputs the notification to the terminal."""print(raw_data)message=raw_data['message']title=raw_data['title']ifraw_data['title']else'_'print(f"{title}\n{message}",end="\n\n")# this instantiates the Pushover websocket class and runs it:client=PushoverOpenClientRealTime()client.run_forever()Command line toolLet’s use Python’sclickto make a fancy interface to this program?A Little More InnerThis package is based in two classes, some decorators to register functions
from user scripts, some functions to register other stuff to be executed by
notifications.The two classes arepython_pushover_open_client.PushoverOpenClientandpython_pushover_open_client.PushoverOpenClientRealTime. The first manages
credentials, authentication, device registration, message downloading,
message deletion etc, like specified by thePushover Open Client API
documentation, and is consumed by the second class. The second class connects
to the Pushover’s websocket server with the given credentials (secretanddevice_id) and keep the connection open, receiving messages and executing
callbacks when and according to each server message is received.By now, decorators and top level functions are used to register functions to
be executed when certain commands are received by notification
(@register_command,@register_command_parser,register_shell_command(),register_shell_command_alias()),
or to register parsers which will be executed when every notification is
received@register_parser.)ContributingPlease open an issue if you want to contribute with code. Or use discussions.The sources’ package in reality contain only two files:__init__.py- This contains thepython_pushover_open_clientlibrary itself.__main__.py- Will hold the command-line interface logic for thepushover-open-clientcommand as it is developed.SupportYou can open a issue or a message in discussions for support in using/getting
the code.Is it ready already?100%NoteThis project has been set up using PyScaffold 4.1.4. For details and usage
information on PyScaffold seehttps://pyscaffold.org/.