V
V
vadimeasy2021-11-09 14:59:52
Python
vadimeasy, 2021-11-09 14:59:52

How to perform consistent data validation in Google Seets?

There is a table (I can’t show the key in full) here I read the key and ID, ID is the page identifier in the working comment. Now my program takes the key from the first column, performs a check on a certain site, and depending on the result of the check, it either sends a comment to the workspace that everything is fine with the key and you can use it.
618a60f3cde05804058166.png
The problem is that I had 76 keys, now out of 130, and my programming strength was enough to prescribe the processing of each cell with writing to a variable and checking. I got 4000 lines for 76 keys, maybe there is some simpler way, somehow write the check into a function and call it for each variable, but I just can’t figure out how and with what help I can do it. This is what a block of 2 cells looks like:

try:
    values_guid = service.spreadsheets().values().get(
        spreadsheetId=spreadsheet_id,
        range='A3:A3',
        majorDimension='COLUMNS'
    ).execute()
    res = values_guid['values'][0][0]

    values_id1 = service.spreadsheets().values().get(
        spreadsheetId=spreadsheet_id,
        range='B3:B3',
        majorDimension='COLUMNS'
    ).execute()
    res_id2 = values_id1['values'][0][0]
    res_id_2 = int(res_id2)


    try:
        options = Options()
        options.headless = True
        # driver = webdriver.Chrome()
        driver = webdriver.Chrome(chrome_options=options)
        
        driver.get(url=url)
        driver.find_element_by_tag_name('input').send_keys(res)
        driver.find_element_by_tag_name('button').click()
        time.sleep(0.5)

        if driver.find_elements_by_xpath('//span[@class="label label-success"][1]'):
            if True:
                request = pyrus.models.requests.TaskCommentRequest(text="Подтверждена, убери пожалуйса свой GUID из этой таблицы https://clck.ru/Yh****, action="")
                task = pyrus_client.comment_task(res_id_2, request).task
                res = print('Подтверждена, убери пожалуйса свой GUID из этой таблицы https://clck.ru/YhBqZ')
                    results = service.spreadsheets().values().batchUpdate(spreadsheetId = spreadsheetId, body = {

                
        elif driver.find_elements_by_xpath('//span[@class="label label-warning"][1]'):
            if True:
                request = pyrus.models.requests.TaskCommentRequest(text="", action="")
                task = pyrus_client.comment_task(res_id_2, request).task
                print('')


        elif driver. find_elements_by_tag_name("tbody"):
            if True:
                request = pyrus.models.requests.TaskCommentRequest(text="Площадка не найдена", action="")
                task = pyrus_client.comment_task(res_id_2, request).task
                print('Ошибка, площадка не найдена.')


    except Exception as ex:
        print(ex)
    finally:
        driver.close()
        driver.quit()
        
except KeyError: 
    pass

I would also like to know how I can, under a certain condition, delete the key and ID from the table, I found one method, but for some reason it does not work inside the if.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vindicar, 2021-11-09
@vadimeasy

I got 4000 lines for 76 keys

I hope you are familiar with the concept of a cycle? o_o
range='A3:A3',

Just generate a range value.
for row in range(3, 130):
    values_guid = service.spreadsheets().values().get(
        spreadsheetId=spreadsheet_id,
        range=f'A{row}:A{row}',
        majorDimension='COLUMNS'
    ).execute()
    #ну и так далее

Instead of a for loop over a fixed range, you can make a while loop, and break it when you stumble upon an empty cell. Then you do not have to prescribe the number of cells.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question