Remove mysql connector and misc code #180
This commit is contained in:
parent
2a469dd469
commit
deff9b7f74
1 changed files with 5 additions and 31 deletions
|
|
@ -9,28 +9,14 @@ import os
|
||||||
import mysql.connector
|
import mysql.connector
|
||||||
import json
|
import json
|
||||||
|
|
||||||
def mysql_connect(user, password, host, database):
|
def init_subscriptions(client):
|
||||||
conn = mysql.connector.connect(user=user,
|
print "subscribing to wildcard"
|
||||||
password=password,
|
client.subscribe('#')
|
||||||
host=host,
|
|
||||||
database=database)
|
|
||||||
return conn
|
|
||||||
|
|
||||||
def init_subscriptions(client, conn):
|
|
||||||
# given mysql connection, get all rider sessions
|
|
||||||
query = ("select id from rider_session")
|
|
||||||
cursor = conn.cursor()
|
|
||||||
cursor.execute(query)
|
|
||||||
for (id) in cursor:
|
|
||||||
print "subscribing to rider session %s" % id
|
|
||||||
client.subscribe('motorider_%s' % id)
|
|
||||||
cursor.close()
|
|
||||||
|
|
||||||
def on_connect(client, userdata, flags, rc):
|
def on_connect(client, userdata, flags, rc):
|
||||||
conn = mysql_connect('resq', 'Motolite456', '127.0.0.1', 'resq')
|
init_subscriptions(client)
|
||||||
init_subscriptions(client, conn)
|
|
||||||
print("Connected with result code "+str(rc))
|
print("Connected with result code "+str(rc))
|
||||||
client.subscribe("$SYS/#")
|
# client.subscribe("$SYS/#")
|
||||||
|
|
||||||
def on_publish(client, userdata, mid):
|
def on_publish(client, userdata, mid):
|
||||||
pass
|
pass
|
||||||
|
|
@ -62,18 +48,6 @@ def on_message(client, userdata, message):
|
||||||
redis_conn.setex(key, 1600, message.payload)
|
redis_conn.setex(key, 1600, message.payload)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def getRedis(i):
|
|
||||||
r = redis.StrictRedis(host='localhost', port=6379, db=0)
|
|
||||||
while 1:
|
|
||||||
time.sleep(0)
|
|
||||||
data = r.brpop("events", 10)
|
|
||||||
if data:
|
|
||||||
info = data[1].split('|')
|
|
||||||
print "Channel: " + info[0] + " message: " + info[1]
|
|
||||||
client.publish(info[0], info[1])
|
|
||||||
|
|
||||||
|
|
||||||
def sigint_handler(signal, frame):
|
def sigint_handler(signal, frame):
|
||||||
print 'Interrupted'
|
print 'Interrupted'
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue