forked from jlemon/zlogger
-
Notifications
You must be signed in to change notification settings - Fork 0
/
monitor_chat.py
41 lines (35 loc) · 1.18 KB
/
monitor_chat.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
import time
import sys
import json
import argparse
import sqlite3
import traceback
import pika
import mysql.connector
from mysql.connector import errors as mysql_errors
def callback(ch, method, properties, body):
data = json.loads(body)
print("[%s] %s" % (data.get('partialName', data.get('riderid', '???')), data['msg']))
def main(argv):
parser = argparse.ArgumentParser(description = 'Race Result Generator')
parser.add_argument('--pika_url', default='amqp://guest:guest@localhost:5672/%2F')
args = parser.parse_args()
parameters = pika.URLParameters(args.pika_url)
connection = pika.BlockingConnection(parameters)
channel = connection.channel()
result = channel.queue_declare(exclusive=True)
queue_name = result.method.queue
channel.queue_bind(exchange='zlogger', queue=queue_name, routing_key='CHAT.#')
try:
channel.basic_consume(callback, queue=queue_name, no_ack=True)
channel.start_consuming()
except KeyboardInterrupt:
connection.close()
if __name__ == '__main__':
try:
main(sys.argv)
except KeyboardInterrupt:
print "exiting"
exit()
except SystemExit, se:
print "ERROR:", se