-
Notifications
You must be signed in to change notification settings - Fork 0
/
send_sms.py
33 lines (27 loc) · 898 Bytes
/
send_sms.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
import requests
import config
def send_sms(message, test_flag=0):
"""
Sends SMS using txtlocal.co.uk API
args:
message (str): The message text to be sent.
test_flag (int): 1 to enable to test_mode (no sms sent), 0 to send sms
"""
username = config.TXTLOCAL_USERNAME
sender = config.TXTLOCAL_SENDER
apihash = config.TXTLOCAL_API_HASH
url = 'https://api.txtlocal.com/send/'
numbers = config.TXTLOCAL_NUMBERS
params = {
'test' : test_flag,
'username': username,
'hash' : apihash,
'message' : message[:160],
'sender' : sender,
'numbers' : numbers }
print('Attempting to send SMS...')
try:
response = requests.get(url, params)
print('Message sent. Status code: ', response.status_code)
except Exception as e:
print('An error occured: ', e)