-
-
Notifications
You must be signed in to change notification settings - Fork 81
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added genpushover.py and genpushover.conf. Thanks @sjbader
- Loading branch information
Showing
2 changed files
with
166 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
|
||
[genpushover] | ||
# APP ID | ||
# account | ||
appid = abc123 | ||
|
||
# USER ID | ||
# acct | ||
userid = 123abc | ||
|
||
# Notification sound | ||
# Full list at https://pushover.net/api#sounds | ||
pushsound = updown |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,153 @@ | ||
#!/usr/bin/env python | ||
#------------------------------------------------------------ | ||
# FILE: genpushover.py | ||
# PURPOSE: genpushover.py sends Push notifications to Android, iOS and Desktop | ||
# | ||
# AUTHOR: Stephen Bader - Stole a lot of code from gensms.py | ||
# DATE: 09-09-2017 | ||
# | ||
# MODIFICATIONS: | ||
#------------------------------------------------------------ | ||
|
||
import datetime, time, sys, signal, os, threading, socket | ||
import atexit | ||
import mynotify, mylog | ||
import ConfigParser | ||
from chump import Application | ||
|
||
|
||
#---------- Signal Handler ------------------------------------------ | ||
def signal_handler(signal, frame): | ||
|
||
GenNotify.Close() | ||
sys.exit(0) | ||
|
||
#---------- OnRun ------------------------------------------ | ||
def OnRun(Active): | ||
|
||
if Active: | ||
print "Generator Running" | ||
SendNotice("Generator Running") | ||
else: | ||
print "Generator Running End" | ||
|
||
#---------- OnRunManual ------------------------------------------ | ||
def OnRunManual(Active): | ||
|
||
if Active: | ||
print "Generator Running in Manual Mode" | ||
SendNotice("Generator Running in Manual Mode") | ||
else: | ||
print "Generator Running in Manual Mode End" | ||
|
||
#---------- OnExercise ------------------------------------------ | ||
def OnExercise(Active): | ||
|
||
if Active: | ||
print "Generator Exercising" | ||
SendNotice("Generator Exercising") | ||
else: | ||
print "Generator Exercising End" | ||
|
||
#---------- OnReady ------------------------------------------ | ||
def OnReady(Active): | ||
|
||
if Active: | ||
print "Generator Ready" | ||
SendNotice("Generator Ready") | ||
else: | ||
print "Generator Ready End" | ||
|
||
#---------- OnOff ------------------------------------------ | ||
def OnOff(Active): | ||
|
||
if Active: | ||
print "Generator Off" | ||
SendNotice("Generator Off") | ||
else: | ||
print "Generator Off End" | ||
|
||
#---------- OnManual ------------------------------------------ | ||
def OnManual(Active): | ||
|
||
if Active: | ||
print "Generator Manual" | ||
SendNotice("Generator Manual") | ||
else: | ||
print "Generator Manual End" | ||
|
||
#---------- OnAlarm ------------------------------------------ | ||
def OnAlarm(Active): | ||
|
||
if Active: | ||
print "Generator Alarm" | ||
SendNotice("Generator Alarm") | ||
else: | ||
print "Generator Alarm End" | ||
|
||
#---------- OnService ------------------------------------------ | ||
def OnService(Active): | ||
|
||
if Active: | ||
print "Generator Service Due" | ||
SendNotice("Generator Service Due") | ||
else: | ||
print "Generator Servcie Due End" | ||
|
||
#---------- SendNotice ------------------------------------------ | ||
def SendNotice(Message): | ||
|
||
try: | ||
app = Application(appid) | ||
user = app.get_user(userid) | ||
|
||
message = user.create_message( | ||
message = Message, | ||
sound = pushsound) | ||
|
||
message.send() | ||
|
||
print(message.id) | ||
|
||
except Exception as e1: | ||
log.error("Error: " + str(e1)) | ||
print "Error: " + str(e1) | ||
|
||
#------------------- Command-line interface for gengpio -----------------# | ||
if __name__=='__main__': # usage program.py [server_address] | ||
address='127.0.0.1' if len(sys.argv)<2 else sys.argv[1] | ||
|
||
# Set the signal handler | ||
signal.signal(signal.SIGINT, signal_handler) | ||
try: | ||
log = mylog.SetupLogger("client", "/var/log/genpushover.log") | ||
|
||
# read config file | ||
config = ConfigParser.RawConfigParser() | ||
# config parser reads from current directory, when running form a cron tab this is | ||
# not defined so we specify the full path | ||
config.read('/etc/genpushover.conf') | ||
|
||
appid = config.get('genpushover', 'appid') | ||
userid = config.get('genpushover', 'userid') | ||
pushsound = config.get('genpushover', 'pushsound') | ||
|
||
GenNotify = mynotify.GenNotify( | ||
host = address, | ||
onready = OnReady, | ||
onexercise = OnExercise, | ||
onrun = OnRun, | ||
onrunmanual = OnRunManual, | ||
onalarm = OnAlarm, | ||
onservice = OnService, | ||
onoff = OnOff, | ||
onmanual = OnManual, | ||
log = log) | ||
|
||
while True: | ||
time.sleep(1) | ||
|
||
except Exception as e1: | ||
log.error("Error: " + str(e1)) | ||
print "Error: " + str(e1) | ||
|