class BaseDao: def __init__(self): self.db = DBConnection() def insert(self, query): con = None cursor = None try: con = self.db.get_connection() cursor = con.cursor() cursor.execute(query) row_id = cursor.lastrowid return row_id except Exception as e: pass finally: cursor.close() con.close() def select(self, query): pass def update(self, query): pass def delete(self, query): pass
def get_all_stock(): df = ts.get_stock_basics() df['stock'] = df.index df = df.sort_values(by=['stock'], ascending=True) return df['stock'].tolist() def exe(parms): print(parms['code']) get_all_day_data(parms['code'], parms['num'], parms['market']) if __name__ == '__main__': a = time.clock() obj = DBConnection() dbcon = obj.connect2() num = 1 stocks = get_all_stock() parms = [{ 'code': stocks[i], 'num': num, 'market': 1 if str(stocks[i]).startswith('60') else 0 } for i in range(0, len(stocks))] pool = multiprocessing.Pool(processes=2) # result = pool.map(exe, parms) for i in stocks: print(i)
def __init__(self): self.db = DBConnection()
class EmployeeDao: def __init__(self): self.db = DBConnection() @staticmethod def generate_queries(file_content_list): # print(file_content_list) queries = [] for emp in file_content_list: Query = "INSERT INTO employee (name,last_name,age) VALUES ('" Query += emp.f_name + "','" + emp.l_name + "','" + emp.age + "')" # print(emp) # print(Query) queries.append(Query) return queries @staticmethod def generate_query(emp): # print(file_content_list) Query = "INSERT INTO employee (name,last_name,age) VALUES ('" Query += emp.f_name + "','" + emp.l_name + "','" + emp.age + "')" return Query @staticmethod def generate_query_addr(addr): # print(file_content_list) Query = "INSERT INTO address (addr_line_1,addr_line_2,city,pincode,country,emp_id) VALUES ( '" Query += addr.address_line_1 + "','" + addr.address_line_2 + "','" + addr.city + "','" + str(addr.zip_code) + "','" + addr.country + "','" + str(addr.emp_id) + "')" return Query def insert_data(self, employees): # queries = EmployeeDao.generate_queries(employees) # queries = EmployeeDao.generate_queries_user() # print(queries) for emp in employees: query = EmployeeDao.generate_query(emp) con = self.db.get_connection() cursor = con.cursor() cursor.execute(query) emp_id = cursor.lastrowid emp.set_emp_id(emp_id) emp.addr_1.set_emp_id(emp_id) emp.addr_2.set_emp_id(emp_id) addr_1_query = EmployeeDao.generate_query_addr(emp.addr_1) addr_2_query = EmployeeDao.generate_query_addr(emp.addr_2) cursor.execute(addr_1_query) # get generated address id and set it to address object present inside employee.... addr_id_1 = cursor.lastrowid ## emp.addr_1.set_addr_id(addr_id_1) cursor.execute(addr_2_query) addr_id_2 = cursor.lastrowid ## emp.addr_2.set_addr_id(addr_id_2) con.commit() cursor.close() con.close()
from controllers.main_controller import MainController from db.db_connection import DBConnection from PyQt5 import QtWidgets import sys con = DBConnection() app = QtWidgets.QApplication(sys.argv) c = MainController(window=QtWidgets.QMainWindow(), db_connection=con) #c = AdminWindowController(window=QtWidgets.QMainWindow(), db_connection=con) sys.exit(app.exec())
from db.db_connection import DBConnection db = DBConnection()