-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathemit.py
41 lines (39 loc) · 1.4 KB
/
emit.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
##########################################################################################
# Sam - Home and Office Automation Message Emitter
# (Sam Message Emitter)
#
# Version 1.0
#
# Py-AIML or PyAIML Interpreter Personality Slackbot
# Used for both home automation and office automation
#
##########################################################################################
import pika
import sys
import httplib
import urllib
def gethelp():
try:
conn = httplib.HTTPSConnection("api.pushover.net:443")
conn.request("POST", "/1/messages.json",
urllib.urlencode({
"token": "PUSH_OVER_TOKEN",
"user": "PUSH_OVER_USER",
"message": "The alarm interface is unable to connect to the message queue. " + message,
}), { "Content-type": "application/x-www-form-urlencoded" })
conn.getresponse()
except:
print "Something went horribly wrong"
try:
credentials = pika.PlainCredentials('user', 'password')
parameters = pika.ConnectionParameters('IP_ADDRESS', PORT, 'queue', credentials)
connection = pika.BlockingConnection(parameters)
channel = connection.channel()
message = ' '.join(sys.argv[1:]) or "Testing queue"
channel.basic_publish(exchange='messages',
routing_key='',
body=message)
print(" [x] Sent %r" % message)
connection.close()
except:
gethelp()