Beispiel #1
0
def load_user_list():
    conn = db_connection.connect_db()
    cursor = conn.cursor()
    responce = []
    cursor.execute("SELECT * FROM `tb_users`")
    result = cursor.fetchall()
    crows = cursor.rowcount
    i = 0
    if (crows > 0):
        for row in result:
            data_arr = {
                'uID': result[i][0],
                'uName': result[i][1],
                'uPass': result[i][2],
                'add_y': result[i][3],
                'update_y': result[i][4],
                'delete_y': result[i][5]
            }
            responce.append(data_arr)

            i = i + 1
        response_arr = {
            'success': 'success',
            'category_data': responce,
            'massage': '' + str(crows) + ' Items Available.'
        }
    else:
        response_arr = {
            'success': 'false',
            'category_data': responce,
            'massage': '' + str(crows) + ' Items Available.'
        }

    return response_arr
 def compone_section(self, section, id):
     """
     This function take as arguments the section and the id and return a text to insert in xml
     """
     #connect to db
     cur = db_connection.connect_db()
     cursore = cur.cursor(cursorclass=MySQLdb.cursors.DictCursor)
     cursore.execute("SELECT * from " + section + " where HARDWARE_ID=" + id)
     text = ""
     popo = cursore.fetchall()
     #start_sc = time.time()
     text = text + "\t\t\t<" + str.upper(section) + ">\n"
     for i in popo:
         for tr, elem in i.items():
             strutf = str(elem)
             if str(tr) == ("HARDWARE_ID"):
                 pass
             elif str(tr) == ("ID"):
                 pass
             else:
                 #print str(s_elem)
                 #if the element is empty pass otherwise parse the elment in the form
                 if str(elem) == "":
                     pass
                 else:
                     text = text + "\t\t\t\t<" + str(tr) + ">" + cgi.escape(strutf) + "</" + str(tr) + ">\n"
                     #print text
                     #we close the stream of section and return all the text
     text = text + "\t\t\t</" + str.upper(section) + ">\n"
     # end_sc = time.time()
     # time_sc = end_sc - start_sc
     # print text
     # print section + " Execution time ciclo nuovo: " + str(time_sc)
     return text
Beispiel #3
0
def load_category_list():
    conn = db_connection.connect_db()
    cursor = conn.cursor()
    responce = []
    cursor.execute("SELECT * FROM `tb_categories`")
    result = cursor.fetchall()
    crows = cursor.rowcount
    i = 0
    if (crows > 0):
        for row in result:
            #cat_id = result[i][0]
            data_arr = {'id': result[i][0], 'title': result[i][1]}
            responce.append(data_arr)

            i = i + 1
        response_arr = {
            'success': 'success',
            'category_data': responce,
            'massage': '' + str(crows) + ' Items Available.'
        }
    else:
        response_arr = {
            'success': 'false',
            'category_data': responce,
            'massage': '' + str(crows) + ' Items Available.'
        }

    return response_arr
Beispiel #4
0
def get_privillages(user_id):
    conn = db_connection.connect_db()
    cursor = conn.cursor()
    cursor.execute(
        "SELECT uid,add_allowed,update_allowed,delete_allowed FROM tb_users WHERE uid = '"
        + str(user_id) + "'")
    result = cursor.fetchall()

    response = {
        'user_id': result[0][0],
        'add_allowed': result[0][1],
        'update_allowed': result[0][2],
        'delete_allowed': result[0][3]
    }

    return response
 def retrieve(self, id):
     """
     This is the function that retrieve the tab from db
     """
     log_class.info("Inizio a creare la scheda per l'id " + id)
     elements = self.read_config_xml()
     l_account = elements[0]
     l_components = elements[1]
     l_hardware = elements[2]
     l_softwares = elements[3]
     cur = db_connection.connect_db()
     cursor = cur.cursor()
     cursor.execute("SELECT * from hardware where id=" + id)
     for record in cursor.fetchall():
         name_id = str(record[2])
         fop = open(local_variables.expfol + name_id + ".xml", "w")
         fop.write("<?xml version=\"1.0\" encoding=\"ISO-8859-1\" ?>\n")
         fop.write("<REQUEST>\n")
         fop.write("\t<DEVICEID>" + name_id + "</DEVICEID>\n")
         fop.write("\t<CONTENT>\n")
         for i in l_account:
             var = self.compone_section(i, id)
             fop.write(var)
         for q in l_components:
             var = self.compone_section(q, id)
             fop.write(var)
         for s in l_softwares:
             #print s
             var = self.compone_section(s, id)
             fop.write(var)
         for w in l_hardware:
             var = self.compone_section_hardware(w, id)
             fop.write(var)
         fop.write("\t</CONTENT>\n")
         fop.write("\t<QUERY>INVENTORY</QUERY>\n")
         fop.write("</REQUEST>\n")
         fop.close()
         filter = re.search(r'(sottorete*)', name_id)
         if name_id == "_SYSTEM":
             pass
         elif filter:
             pass
         else:
             html.xml_to_pdf(name_id + ".xml", local_variables.upfol+"ocs.xsl")
         log_class.info(time.asctime() + " - file " + name_id + ".xml creato.\n")
     cur.close()
Beispiel #6
0
def check_user(username, password):
    conn = db_connection.connect_db()
    cursor = conn.cursor()
    cursor.execute("SELECT uid FROM tb_users WHERE uName = '" + username +
                   "' AND uPass = '******'")
    result = cursor.fetchall()
    crows = cursor.rowcount

    session['logged_in'] = True
    session['user_id'] = result[0][0]

    #if(crows > 0):
    #session['logged_in'] = True
    #session['user_id'] = result[0][0]
    #else:
    #return redirect(url_for('login_user'))

    return crows
Beispiel #7
0
def delete_prod(p_id):
    response = []
    conn = db_connection.connect_db()
    cursor = conn.cursor()
    try:
        cursor.execute("DELETE FROM tb_products WHERE prdtId='" + p_id + "'")
        conn.commit()
    except Exception as e:
        error_massage = str(e)
        error_response = {
            'success': 'false',
            'massage': 'Database error occured.' + str(error_massage)
        }
        return error_response
    else:
        response = {
            'success': 'success',
            'massage': 'Item Deleted successfully.'
        }

    return response
Beispiel #8
0
def prd_save(valproduct_desc, txtcat_id):
    conn = db_connection.connect_db()
    cursor = conn.cursor()
    try:
        cursor.execute("INSERT INTO tb_products (prdName,fl_catid) VALUES ('" +
                       valproduct_desc + "'," + txtcat_id + ")")
        conn.commit()
    except Exception as e:
        error_massage = str(e)
        error_response = {
            'success': 'false',
            'massage': 'Database error occured.' + str(error_massage)
        }
        return error_response
    else:
        response = {
            'success': 'success',
            'massage': 'Data Inserted successfully.'
        }

    return response
Beispiel #9
0
def delete_cat(cat_delete):
    response = []
    conn = db_connection.connect_db()
    cursor = conn.cursor()
    try:
        cursor.execute("DELETE FROM tb_categories WHERE fl_catid='" +
                       cat_delete + "'")
        conn.commit()
    except Exception as e:
        error_massage = str(e)
        error_response = {
            'success': 'false',
            'massage': 'Database error occured.' + str(error_massage)
        }
        return error_response
    else:
        response = {
            'success': 'success',
            'massage': 'Item Deleted successfully.'
        }

    return response
Beispiel #10
0
def cat_save(valcategory_desc):
    conn = db_connection.connect_db()
    cursor = conn.cursor()
    try:

        cursor.execute("INSERT INTO tb_categories (fl_catname) VALUES ('" +
                       valcategory_desc + "')")
        conn.commit()
    except Exception as e:
        error_massage = str(e)
        error_response = {
            'success': 'false',
            'massage': 'Database error occured.' + str(error_massage)
        }
        return error_response
    else:
        response = {
            'success': 'success',
            'massage': 'Data Inserted successfully.'
        }

    return response
Beispiel #11
0
def load_product_list():
    conn = db_connection.connect_db()
    cursor = conn.cursor()
    responce = []
    #SELECT * FROM `tb_products` INNER JOIN tb_categories ON tb_products.fl_catid = tb_categories.fl_catid
    cursor.execute(
        "SELECT tb_products.prdtId,tb_products.prdName,tb_categories.fl_catid,tb_categories.fl_catname FROM `tb_products` INNER JOIN tb_categories ON tb_products.fl_catid = tb_categories.fl_catid"
    )
    result = cursor.fetchall()
    crows = cursor.rowcount
    i = 0
    if (crows > 0):
        for row in result:
            #cat_id = result[i][0]
            data_arr = {
                'prdId': result[i][0],
                'prdName': result[i][1],
                'catid': result[i][2],
                'catName': result[i][3]
            }
            responce.append(data_arr)

            i = i + 1
        response_arr = {
            'success': 'success',
            'category_data': responce,
            'massage': '' + str(crows) + ' Items Available.'
        }
    else:
        response_arr = {
            'success': 'false',
            'category_data': responce,
            'massage': '' + str(crows) + ' Items Available.'
        }

    return response_arr
Beispiel #12
0
def user_save(valtxtusername, valtxtpassword, valchkadd, valchkupdate,
              valchkdelete):
    conn = db_connection.connect_db()
    cursor = conn.cursor()
    try:
        cursor.execute(
            "INSERT INTO tb_users (uName,uPass,add_allowed,update_allowed,delete_allowed) VALUES ('"
            + valtxtusername + "','" + valtxtpassword + "'," + valchkadd +
            "," + valchkupdate + "," + valchkdelete + ")")
        conn.commit()
    except Exception as e:
        error_massage = str(e)
        error_response = {
            'success': 'false',
            'massage': 'Database error occured.' + str(error_massage)
        }
        return error_response
    else:
        response = {
            'success': 'success',
            'massage': 'Data Inserted successfully.'
        }

    return response
Beispiel #13
0
import datetime

import db_connection
from Helpers import string_helper

# Main Code starts here!!!

focal_wallet_addr_list = ['0xe2dbd4756f1749e20ed7f891403e70543e25298a']

print(focal_wallet_addr_list, "\n")

# conn_str = 'host=server2 port=5432 dbname=postgres user=sina13890'
# conn = psycopg2.connect(conn_str)

conn = db_connection.connect_db('postgres')

cursor = conn.cursor()

query = """
            SELECT 
                pk_id, erc20_token, erc20_from, erc20_to, erc20_value, block_timestamp
            FROM 
                eth_cleaned.tmp_erc20_xfers_tamp__v2 E
            WHERE 
                erc20_from = %s
                OR
                erc20_to = %s
            ORDER BY 
                block_timestamp;
        """
data = (focal_wallet_addr_list[0], focal_wallet_addr_list[0])