def fill_workers_db(): workers = [ Worker("Jan", "Kowalski"), Worker("Anna", "Nowak"), Worker("Tomasz", "Armstrong"), Worker("Zuzanna", "Mozart"), Worker("Antoni", "Skłodowski") ] connection = sql.connect(database_name) for i in range(len(workers)): cursor = connection.cursor() w = workers[i] cursor.execute("INSERT INTO workers_database VALUES (?,?,?,?)", (w.number, w.name, w.surname, w.card)) connection.commit() connection.close()
def get_workers_array(): connection = sql.connect(database_name) cursor = connection.cursor() cursor.execute("SELECT * FROM workers_database") emp = cursor.fetchall() output = [] for worker in emp: output.append(Worker(worker[1], worker[2], worker[0], calc_card_num(worker[3]))) return output
def print_workers(): connection = sql.connect(used_database) cursor = connection.cursor() cursor.execute("SELECT * FROM workers_database") emp = cursor.fetchall() w_arr = [] for worker in emp: w_arr.append(Worker(worker[1], worker[2], worker[0], worker[3])) for w in w_arr: print(str(w))
def findWorker(workerId): connection = sql.connect(used_database) cursor = connection.cursor() cursor.execute("SELECT * FROM workers_database") emp = cursor.fetchall() for worker in emp: if int(worker[0]) == workerId: worker_name = worker[1] worker_surname = worker[2] worker_id = int(worker[0]) card_id = calc_card_num(worker[3]) return Worker(worker_name, worker_surname, worker_id, card_id) return None
def add_worker(): print("__Adding worker__") check = True while check: name = input("Input the name: ") surname = input("Input the surname: ") inp = 'O' while inp != 'N' and inp != 'Y': inp = input(f"Is data: {name} {surname} correct?[Y/N]") if inp == 'Y': check = False worker = Worker(name, surname) add_worker_to_db(worker) print(f"{worker} successfully added to database") elif inp == 'N': print("Data incorrect, input again...") else: print("Please insert (Y)es or (N)o")