Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
Added genpushover.py and genpushover.conf. Thanks @sjbader
  • Loading branch information
jgyates authored Sep 11, 2017
1 parent 7cb2660 commit 617bb19
Show file tree
Hide file tree
Showing 2 changed files with 166 additions and 0 deletions.
13 changes: 13 additions & 0 deletions genpushover.conf
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
153 changes: 153 additions & 0 deletions genpushover.py
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)

0 comments on commit 617bb19

Please sign in to comment.