forked from onlinecity/kannel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsendsms
executable file
·47 lines (40 loc) · 1.03 KB
/
sendsms
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
#!/usr/bin/python
import os, string, sys, urllib
HOST = "localhost"
PORT = 13013
USERNAME = "tester"
PASSWORD = "foobar"
NUMBERS = "~/.sendsms.dat"
def is_a_phone_number(str):
if not str:
return 0
for c in str:
if not c in "0123456789+- ":
return 0
return 1
def recipient(arg):
if is_a_phone_number(arg):
return arg
f = open(os.path.expanduser(NUMBERS), "r")
arg = string.lower(arg)
number = None
for line in f.readlines():
parts = string.split(line)
if len(parts) == 2 and string.lower(parts[0]) == arg:
number = parts[1]
break
f.close()
if number:
return number
print "Unknown recipient", arg
sys.exit(1)
def sendsms():
to = urllib.quote_plus(recipient(sys.argv[1]))
text = urllib.quote_plus(string.join(sys.argv[2:], " "))
url="http://%s:%d/cgi-bin/sendsms?username=%s&password=%s&to=%s&text=%s" \
% (HOST, PORT, USERNAME, PASSWORD, to, text)
f = urllib.urlopen(url)
print f.read()
f.close()
if __name__ == "__main__":
sendsms()