2013-11-15 16:08:41 +01:00
|
|
|
'''
|
|
|
|
|
Created on 15.11.2013
|
|
|
|
|
|
|
|
|
|
@author: Philipp Rauch
|
|
|
|
|
@version: 0.01
|
|
|
|
|
'''
|
|
|
|
|
|
|
|
|
|
import MySQLdb
|
|
|
|
|
import threading
|
|
|
|
|
import Queue
|
2013-11-19 17:11:25 +01:00
|
|
|
from CANFilter import CANFilter
|
2013-11-15 16:08:41 +01:00
|
|
|
|
|
|
|
|
MYSQL = 0
|
|
|
|
|
CSV = 1
|
|
|
|
|
XML = 2
|
|
|
|
|
JSON = 3
|
|
|
|
|
|
2013-11-19 17:11:25 +01:00
|
|
|
class Swich(threading.Thread):
|
|
|
|
|
|
|
|
|
|
def __init__(self, source = MYSQL):
|
|
|
|
|
threading.Thread.__init__(self)
|
2013-11-15 16:08:41 +01:00
|
|
|
self.source = source
|
2013-11-19 17:11:25 +01:00
|
|
|
|
|
|
|
|
def __del__(self):
|
|
|
|
|
if self.source == MYSQL:
|
|
|
|
|
self.CAN.join()
|
|
|
|
|
|
|
|
|
|
def initialisiere(self):
|
2013-11-15 16:08:41 +01:00
|
|
|
if self.source == MYSQL:
|
2013-11-19 17:11:25 +01:00
|
|
|
self.CAN = CANFilter()
|
|
|
|
|
self.CAN.start()
|
|
|
|
|
|
|
|
|
|
self.connection = MySQLdb.connect("url", "user", "password", "database_name")
|
2013-11-15 16:08:41 +01:00
|
|
|
self.cursor = self.connection.cursor()
|
2013-11-19 17:11:25 +01:00
|
|
|
self.queue = Queue.Queue()
|
|
|
|
|
return self.queue, self.CAN
|
|
|
|
|
|
|
|
|
|
elif self.source == CSV:
|
2013-11-15 16:08:41 +01:00
|
|
|
pass
|
2013-11-19 17:11:25 +01:00
|
|
|
|
2013-11-15 16:08:41 +01:00
|
|
|
elif self.source == XML:
|
|
|
|
|
pass
|
2013-11-19 17:11:25 +01:00
|
|
|
|
2013-11-15 16:08:41 +01:00
|
|
|
elif self.source == JSON:
|
|
|
|
|
pass
|
2013-11-19 17:11:25 +01:00
|
|
|
|
2013-11-15 16:08:41 +01:00
|
|
|
else:
|
|
|
|
|
return
|
2013-11-19 17:11:25 +01:00
|
|
|
|
|
|
|
|
def run(self):
|
|
|
|
|
while True:
|
|
|
|
|
sql = 'SELECT * FROM %s ORDER BY timestamp DESC LIMIT 1'
|
|
|
|
|
item = Swich.queue.get(block = True) #item is a string which names the table that will be returned (newest values)
|
|
|
|
|
|
|
|
|
|
print self.cursor.execute(sql % item)
|
|
|
|
|
|
|
|
|
|
def setQueue(self, item):
|
|
|
|
|
self.queue.put(item)
|