Esempio n. 1
0
def getter(msg):
    msg_as_str = msg.decode('utf-8')    
    msg_as_dict = fix_json_quotings(msg_as_str)
    
    try:
        conn = MSQL(get_conf(['DBs',msg_as_dict['db'],'db_cred','host']),
                get_conf(['DBs',msg_as_dict['db'],'db_cred','user']),
                str(get_conf(['DBs',msg_as_dict['db'],'db_cred','password'])),
                msg_as_dict['db'])
    except:
        return("ERROR: couldn't connect with given credentials")
    
    msg_as_dict.pop('db')
    table = msg_as_dict.pop('table')

    if 'record_id' in msg_as_dict:
        result = conn.find_record(table,msg_as_dict['record_id'])
    elif len(msg_as_dict)==0:
        result = conn.find_all_records(table)
        result = list_of_tuples_to_list_of_lists(result)
    else:
        column =  str(list(msg_as_dict.keys())[0])
        value = str(list(msg_as_dict.values())[0])
        result = conn.find_records(table, column, value)
        print(result)
        if type(result) == type(['list','list']):
            result = list_of_tuples_to_list_of_lists(result)
        else:
            pass
    return(result)
Esempio n. 2
0
def deleter(msg):
    msg_as_str = msg.decode('utf-8')
    msg_as_dict = fix_json_quotings(msg_as_str)

    try:
        conn = MSQL(
            get_conf(['DBs', msg_as_dict['db'], 'db_cred', 'host']),
            get_conf(['DBs', msg_as_dict['db'], 'db_cred', 'user']),
            str(get_conf(['DBs', msg_as_dict['db'], 'db_cred', 'password'])),
            msg_as_dict['db'])
    except:
        return ("ERROR: couldn't connect with given credentials")

    result = conn.delete_record(msg_as_dict['table'], msg_as_dict['record_id'])
    return (result)
Esempio n. 3
0
def poster(msg):
    msg_as_str = msg.decode('utf-8')    
    msg_as_dict = fix_json_quotings(msg_as_str)
    
    try:
        conn = MSQL(get_conf(['DBs',msg_as_dict['db'],'db_cred','host']),
                get_conf(['DBs',msg_as_dict['db'],'db_cred','user']),
                str(get_conf(['DBs',msg_as_dict['db'],'db_cred','password'])),
                msg_as_dict['db'])
    except:
        return("ERROR: couldn't connect with given credentials")
    msg_as_dict.pop('db')
    table = msg_as_dict.pop('table')
    
    record = conn.insert_record(table, tuple(msg_as_dict.keys()), tuple(msg_as_dict.values()))
    return(record)
Esempio n. 4
0
        is_conf_up = True
    except:
        pass
print("PUT consumer awaiting connection to RabbitMQ")
while is_rabbit_up is False:
    try:
        rab = Rabbit(host=get_conf(['RabbitMQ', 'host']))
        is_rabbit_up = True
        rab.close_connection()
    except:
        pass
print("PUT consumer awaiting connection to MySQL")
while is_mysql_up is False:
    try:
        mas = conn = MSQL(get_conf(['mysql_cred','host']),
                get_conf(['mysql_cred','user']),
                str(get_conf(['mysql_cred','password'])))
        is_mysql_up = True
        dbs =  get_conf(['DBs'])
        for db in dbs:
            conn.create_db(db)
            print(db + " db initialized")
            tables = get_conf(['DBs', db, 'tables'])
            for table in tables:
                conn.create_table(table, get_conf(['DBs', db, 'tables', table]))
                print(table + " table initialized")
    except:
        pass

# After initializing a rabbit object and declare the queue it will consume from.
consumer = Rabbit(host=get_conf(['RabbitMQ', 'host']))
Esempio n. 5
0
from pyTools.extra_tools import get_conf
from pyTools.MySQL_Class.MySQL_Class import MSQL

# a simple script that iterates through the config an initialized the databases and tables.

conn = MSQL(get_conf(['mysql_cred', 'host']), get_conf(['mysql_cred', 'user']),
            str(get_conf(['mysql_cred', 'password'])))

dbs = get_conf(['DBs'])
for db in dbs:
    conn.create_db(db)
    print(db + " db initialized")
    tables = get_conf(['DBs', db, 'tables'])
    for table in tables:
        conn.create_table(table, get_conf(['DBs', db, 'tables', table]))
        print(table + " table initialized")