-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patholark-hipchat.py
More file actions
85 lines (65 loc) · 2.43 KB
/
Copy patholark-hipchat.py
File metadata and controls
85 lines (65 loc) · 2.43 KB
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import logging
import Queue
import signal
import time
import sys
import os
sys.path.append(os.path.join(os.path.dirname(__file__)))
import config
from olarkclient import Olark
from hipchatclient import HipChat
from threading import Thread
logging.basicConfig(level=logging.ERROR)
class OlarkHipchat(Thread):
def __init__(self, sleep_delay, hipchat_client, olark_client):
super(OlarkHipchat, self).__init__()
self.sleep_delay = sleep_delay
self.running = True
self.hipchat_client = hipchat_client
self.olark_client = olark_client
def run(self):
while self.running:
# monitor if there is a participant in the HipChat room
participants = self.hipchat_client.get_participants()
# get the olark client state
olark_state = self.olark_client.state.current_state()
print "HipChat operators: %s | Olark state: %s" % (participants, olark_state)
# if participants and olark client is not connected
if participants and olark_state != "connected":
# connect it
if self.olark_client.connect(("olark.com", 5222)):
print "Connecting to olark..."
self.olark_client.process()
# if no participant, disconnect olark client
elif not participants and olark_state == "connected":
print "Disconnecting from olark..."
self.olark_client.disconnect()
# wait to check again Hipchat participants
time.sleep(self.sleep_delay)
def stop(self):
self.running = False
if __name__ == '__main__':
# create the queue
queue = Queue.Queue(maxsize=0)
# create clients for Olark and HipChat
hipchat_client = HipChat(queue, config.HIPCHAT_TOKEN, config.HIPCHAT_ROOMNAME)
hipchat_client.start()
olark_client = Olark(queue, config.OLARK_USERNAME, config.OLARK_PASSWORD, config.HIPCHAT_ROOMNAME)
# create the watch dog
client = OlarkHipchat(config.HIPCHAT_SLEEPDELAY, hipchat_client, olark_client)
client.start()
# CTRL + C -> quit the application
def handler(signum, frame):
client.stop()
try:
olark_client.abort()
except:
pass
try:
hipchat_client.stop()
except:
pass
signal.signal(signal.SIGINT, handler)
signal.pause()