-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathprowlgooglevoice.py
68 lines (63 loc) · 1.75 KB
/
prowlgooglevoice.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
from googlevoicenotify import GoogleVoiceNotify
from time import sleep
from os import environ, path
import sys
from getpass import getpass
class ProwlListener:
def __init__(self,prowlkey = environ['HOME']+'/.prowlapi'):
if not path.exists(prowlkey):
# fallback to prowlkey in the same folder
prowlkey = 'prowlkey'
PROWL_API_KEY = file(prowlkey, 'r').read().strip()
import prowlpy
self.prowl = prowlpy.Prowl(PROWL_API_KEY)
def on_notification(self, event, from_name, message):
self.prowl.add('%s' % event,from_name, message)
class PrintListener:
def on_notification(self, event, name, message):
print "%s: %s said %s" % (event, name, message)
def readparams(cfile):
params = dict()
try:
for ln in open(cfile).readlines():
if not ln[0] in ('#',';'):
key,val = ln.strip().split('=',1)
params[key.lower()] = val
except:
print 'cfile not read.'
try:
params['gvid']
except:
params['gvid'] = raw_input('Google login: ')
try:
params['password']
except:
params['password'] = getpass('%s password: '%params['gvid'])
try:
params['sleep']
except:
params['sleep'] = 60
return params['sleep'], params['gvid'], params['password']
if __name__ == '__main__':
try:
prowl_listener = ProwlListener()
print_listener = PrintListener()
except Exception, e:
print e
print 'Could not load ProwlListener...exiting.'
sys.exit()
cfile = environ['HOME']+'/.gvnotify'
try:
sleep_time, name, passwd = readparams(cfile)
except:
print 'Could not load Google Voice info...exiting.'
sys.exit()
gv = GoogleVoiceNotify(name, passwd,
listeners=(prowl_listener, print_listener),
picklefile = environ['HOME']+'/.gvcache')
del passwd
while True:
# uncomment below for debugging
# print 'sleeping...'
gv.check()
sleep(sleep_time)