Skip to content

Instantly share code, notes, and snippets.

@alexrudy
Last active November 5, 2023 14:45
Show Gist options
  • Save alexrudy/bd35198aaebf25b2d784b93efb88efa0 to your computer and use it in GitHub Desktop.
Save alexrudy/bd35198aaebf25b2d784b93efb88efa0 to your computer and use it in GitHub Desktop.
Send yourself a notification via pushover.
#!/usr/bin/env python
#
# pushover.py
# Send yourself notifications via https://pushover.net
# Just set your pushover user ID to PUSHOVER_USER_ID
# and your application API token to PUSHOVER_API_TOKEN
# then call this script with the message you want to
# send::
#
# $ make test; pushover.py "make test finished!"
#
# Copyright 2017 Alexander Rudy. All rights reserved.
#
import sys
import os
import requests
USER = os.environ['PUSHOVER_USER_ID']
API = os.environ['PUSHOVER_API_TOKEN']
def send_message(text):
"""Send a message"""
payload = {"message": text, "user": USER, "token": API }
r = requests.post('https://api.pushover.net/1/messages.json', data=payload, headers={'User-Agent': 'Python'})
return r
def main():
"""Main function for this script."""
r = send_message(" ".join(sys.argv[1:]))
if not r.status_code == 200:
print(r.text)
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment