-
Notifications
You must be signed in to change notification settings - Fork 1
/
send-billing-message.py
executable file
·42 lines (31 loc) · 1.22 KB
/
send-billing-message.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
#!/usr/bin/env python
import time
import boto.sqs
import json
from twilio.rest import TwilioRestClient
#import creds
ACCOUNT_SID = "AC748702fc738d6f16455dd418b93a67d1"
AUTH_TOKEN = "cc2ceaa0b0335037b72d132582fc3c88"
def main():
conn = boto.sqs.connect_to_region("ap-southeast-1")
billing_queue = conn.get_queue('billing-queue')
while True:
print "Long polling billing queue ...", billing_queue._arn()
sqs_message_list = billing_queue.get_messages(num_messages=1, wait_time_seconds=20)
if sqs_message_list:
sqs_message = sqs_message_list[0]
json_message = json.loads(sqs_message.get_body())
text_message = "//".join([json_message.get('TopicArn'), json_message.get('Subject'), json_message.get('Message')])
print "Sending message ...", text_message
client = TwilioRestClient(ACCOUNT_SID, AUTH_TOKEN)
twilio_message = client.messages.create(to="+971528703911", from_="+14805265812", body=text_message,)
billing_queue.delete_message(sqs_message)
else:
print "No message found on the billing queue ..."
print "Sleeping for 10 seconds .."
time.sleep(10)
if __name__=='__main__':
try:
main()
except Exception as e:
print "Error: ", e.message