-
Notifications
You must be signed in to change notification settings - Fork 0
/
sendSMS.py
executable file
·46 lines (36 loc) · 1.32 KB
/
sendSMS.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
#!/usr/bin/python3
import sys
import urllib
from urllib import parse
from urllib import request
from accounts import Accounts
def writeRawMsg(rawMsg, user='cf'):
if user is None:
user = 'cf'
values = Accounts.accounts[user]
# print("rawMsg " + repr(rawMsg))
# because \n is not managed by free mobile, we need to replace it by \r
rawMsgFiltered = rawMsg.decode().replace('%0A%0D', '%0A').replace('%0D', '%0A')
data = urllib.parse.urlencode(values)
req = urllib.request.Request(Accounts.the_url + '?' + data + '&' + rawMsgFiltered)
handle = urllib.request.urlopen(req)
the_page = handle.read()
def writeMsgUser(msg, user='cf'):
if user is None:
user = 'cf'
values = Accounts.accounts[user]
filtered_msg = msg.replace('\r\n', '\r').replace('\n', '\r')
values['msg'] = filtered_msg.encode('utf-8')
data = urllib.parse.urlencode(values)
# req = urllib.request.Request(the_url, data)
print(Accounts.the_url + '?' + data)
req = urllib.request.Request(Accounts.the_url + '?' + data)
handle = urllib.request.urlopen(req)
the_page = handle.read()
def writeMsg(msg):
writeMsgUser(msg, 'cf')
if __name__ == '__main__':
if len(sys.argv) > 1:
writeMsg(" ".join(sys.argv[1:]))
else:
writeMsg('Hello from Raspberry pi! (message vide)')