def process_card(message_decoded):
    global last_card, is_empty, reading
    if reading:
        card = Card(calc_card_num(message_decoded[0]))
        last_card = card
        is_empty = False
        reading = False
예제 #2
0
def get_cards_array():
    connection = sql.connect(used_database)
    cursor = connection.cursor()
    cursor.execute("SELECT * FROM cards_database")
    cards_db = cursor.fetchall()
    output = []
    for card in cards_db:
        output.append(Card(calc_card_num(card[0])))
    return output
예제 #3
0
def fill_cards_db(count):
    connection = sql.connect(database_name)
    for i in range(count):
        card = Card()
        cursor = connection.cursor()
        cursor.execute("INSERT INTO cards_database VALUES (?)",
                       (str(card.uid), ))
        connection.commit()
    connection.close()
예제 #4
0
def register_unrecognized_card(message):
    card = Card(calc_card_num(message[0]))
    terminal = message[1]
    use_time = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
    print(f"{use_time}, unknown card: {card} was used at {terminal}")
    connection = sql.connect(used_database)
    cursor = connection.cursor()
    cursor.execute("INSERT INTO unrecognized_table VALUES (?,?,?)",
                   (str(card.uid), use_time, terminal))
    connection.commit()
    connection.close()
예제 #5
0
def load_cards():
    connection = sqlite3.connect(used_database)
    cursor = connection.cursor()
    cursor.execute("SELECT * FROM cards_database")
    cards_db = cursor.fetchall()
    cards = []
    for card in cards_db:
        cards.append(Card(calc_card_num(card[0])))
    connection.commit()
    connection.close()
    return cards
def mainLoop():
    cards = _setup.load_cards()
    print_menu()
    while True:
        if keyboard.is_pressed('b'):
            time.sleep(0.3)
            scan_card(cards[0])
        if keyboard.is_pressed('n'):
            time.sleep(0.3)
            scan_card(cards[1])
        if keyboard.is_pressed('m'):
            time.sleep(0.3)
            scan_card(cards[7])
        if keyboard.is_pressed(','):
            time.sleep(0.3)
            scan_card(Card())
예제 #7
0
def process_card_id(message_decoded):
    if message_decoded[0] != "Client connected" and message_decoded[
            0] != "Client disconnected":
        card = Card(calc_card_num(message_decoded[0]))
        if card in get_cards_array():
            workersID = findAssignedWorkersID(card)
            terminal = str(message_decoded[1])
            use_time = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
            print(f"{use_time}, {card} was used by {workersID} at {terminal}")
            # Save to sqlite database.
            connection = sql.connect(used_database)
            cursor = connection.cursor()
            cursor.execute('''INSERT INTO workers_log VALUES (?,?,?,?)''',
                           (use_time, terminal, str(card.uid), workersID))
            connection.commit()
            connection.close()
        else:
            print("Card not approved! This incident will be registered!")
            register_unrecognized_card(message_decoded)
    else:
        print(message_decoded[0] + " : " + message_decoded[1])
예제 #8
0
def mainLoop():
    while True:  # making a loop
        # run mode
        if keyboard.is_pressed('q'):
            press_card(cards[0])
            time.sleep(0.3)

        if keyboard.is_pressed('w'):
            press_card(cards[1])
            time.sleep(0.3)

        if keyboard.is_pressed('e'):
            press_card(cards[2])
            time.sleep(0.3)

        if keyboard.is_pressed('p'):
            press_card(Card())
            time.sleep(0.3)

        if keyboard.is_pressed('esc'):
            break