forked from sklnd/cli2phone
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cli2phone.py
executable file
·62 lines (46 loc) · 1.34 KB
/
cli2phone.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
#!/usr/bin/env python
"""cli2phone pushes messages from the command line to your android phone.
Requires Android 2.2 or newer, and the chrometophone application installed.
See: http://code.google.com/p/chrometophone/
Usage: cli2phone [--reauth] URL
"""
import sys
import getopt
from auth import Auth
apiVersion = '5'
baseUrl = 'https://chrometophone.appspot.com/send?ver=' + apiVersion
def main(argv=None):
do_reauth = False
if argv is None:
argv = sys.argv
try:
opts, args = getopt.getopt(sys.argv[1:], "hr", ["help", "reauth"])
except getopt.error, msg:
print msg
print "for help use --help"
sys.exit(2)
# process options
for o, a in opts:
if o in ("-h", "--help"):
print __doc__
sys.exit(0)
elif o in ("-r", "--reauth"):
print "Forcing reauthentication."
do_reauth = True
# process arguments
if len(args) == 0:
print __doc__
else:
for arg in args:
send_url(arg, do_reauth)
def send_url(url, reauth):
"""Sends a URL to the phone"""
params = {'url': url,
'title': '',
'sel': '',
'type': '',
'deviceType': 'ac2dm'}
auth = Auth(reauth=reauth)
auth.request(baseUrl, params)
if __name__ == "__main__":
sys.exit(main())