''' Created on 26.11.2013 @author: Philipp Rauch ''' from MySQLdb import connect def setup(conf): ''' establishes a connection to the database and returns a cursor @return: cursor to the database ''' connection = connect(host = conf['mySQL_server'], user = conf['mySQL_user'], passwd = conf['mySQL_pass'], db = conf['mySQL_database'], port = int(conf['mySQL_port'])) cursor = connection.cursor() return cursor def loop(cursor, item): ''' ''' sql_values = 'SELECT * FROM %s ORDER BY DateTime DESC LIMIT 1' sql_collums = 'SHOW COLUMNS FROM %s' path = item.split('/') if path[0] == '': path.remove('') collums = [] cursor.execute(sql_collums % path[len(path) -1]) for cul in cursor: collums.append(cul[0]) cursor.execute(sql_values % path[len(path) -1]) for row in cursor: values = row result = {} for i in range(len(collums)): result[collums[i]] = values[i] # for p in range(len(path)): # result = { path.pop() : result } result = {item : result} return result def close(cursor): pass