Распространенные таблицы Google, находящие значения строк и столбцов в цикле for - PullRequest
0 голосов
/ 23 мая 2019

Я создал эту программу, которая будет запускать скрипт Python с вводом через последовательный порт Arduino. По сути, мой проект - это устройство для приема посетителей, где люди могут входить и выходить из системы с помощью устройства считывания RFID-карт. Как найти связанные точки данных в списке?

Я назначаю строку моих электронных таблиц (например, список имен) переменной. Затем я обыскиваю каждую ячейку, пока не найду правильное имя. Проблема в том, что я хочу найти столбец ячейки, в котором я нашел имя. Я не уверен, как это сделать, но я написал что-то вроде заполнителя + как я хочу, чтобы он работал в строках с пометкой "ссылка пункт 1 "в моем коде.


# Credentials and imports ^^
file = gspread.authorize(credentials) # authenticate with Google
sheet = file.open("RFID-2019-2020-Attendance").sheet1 # open sheet
#placeholder
date_added = False
name_added = False
name_matched = False
current_card_number = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]


def current_card_name():
    for id in id_Numbers:
        if id == current_card_number and name_matched == False:
            matching_name = sheet.cell(id.row,1)
            name_matched = True
    return matching_name


def current_card_number():
        card_num = serial.read_until('*', 28)
        return card_num


while True:
    print('Scan A Card To Sign In')
    id_Numbers = sheet.col_values(2)
    names = sheet.row_values(1, 1)
    dates = sheet.row_values(1)

    for name in names:
        if name.value == current_card_name(): # if card is alread in system
            print('Card Recognized...')
            for date in dates:# check if date is already a headre
                if date == datetime.today().strftime('%Y-%m-%d'):# date is in header
                    # reference point 1
                    sheet.update_cell(date.row,name.column, 'P')
                else:
                    #date not in header
                    for date in dates:# find new open spot in header
                        if date == '' and date_added == False:# if date is non existant
                            # write date in new row
                            sheet.update_cell(date, 1, datetime.today().strftime('%Y-%m-%d'))
                            date_added = True
                        #write "P" in the new date column
                        sheet.update_cell(date.row, name.column, 'P')
                        date_added = False # reset variable after date is added
                        print('Welcome ' + name + '! You Have Been Signed In ')

        else:# if card is not in system
                print('Card not Recognized.')
                print('1) Add new Profile')
                print('2) Go back to main menu')
                print('3) Change card')
                cmd_input = input()
                if cmd_input == '1':
                    print('What is the name associated with this card?')
                    cmd_input = input()
                    for name in names:
                        if name == '' and name_added == False:
                            sheet.update_cell(name.row, 1,cmd_input)# names in first column
                            sheet.update_cell(name.row, 2, current_card_number())#puts card ID in second columnFrea
                            name_added = True
                            print('New profile Created! Returning to main Menu...')
                if cmd_input == '2':
                    print('Returning to main screen...')
                if cmd_input == '3':
                    print('What is the name of the Profile associated with the card?')
                    cmd_input = input()
            # add new card y/n
            # no will take you back to main screen

Я знаю, что это неправильно, поэтому я не запускал его. Буду признателен за любую помощь.

...