Commit b5065176 authored by Giuseppe Tropea's avatar Giuseppe Tropea
Browse files

more robust parsing of googlesheet

parent 7929b96a
Loading
Loading
Loading
Loading
+9 −2
Original line number Diff line number Diff line
import requests
import json

googlesheet_url = "https://docs.google.com/a/google.com/spreadsheets/d/1AfsmGlSyb7rqMgfRSF-S4PpcUyTi7Fhx/gviz/tq?range=A1:N394&headers=1&tq=select%20G%2CI&tqx=out:json"
googlesheet_url = "https://docs.google.com/a/google.com/spreadsheets/d/1AfsmGlSyb7rqMgfRSF-S4PpcUyTi7Fhx/gviz/tq?range=A1:O394&headers=1&tq=select%20A%2CB%2CC%2CD%2CE%2CF%2CG%2CH%2CI%2CJ%2CK%2CL%2CM%2CN%2CO&tqx=out:json"
site_request = requests.get(googlesheet_url)

site_response = str(site_request.content)
@@ -17,13 +17,20 @@ testcaseinfo = []
# the Table is structured as follows:
# - cols: an array of N objects. Each object has an "label" field with the name of the column
# - rows: an array of a zillion objects. Each object has a "c" field that is an array of N sub-objects. Each sub-object has a "v" field that is the target value of the corresponding column
rowcounter = 0
for row in table["rows"]:
    rowcounter += 1
    print(rowcounter)
    column_index = 0
    testcase = {}
    for column in row["c"]:
        print("  "+str(column_index+1))
        column_label = table["cols"][column_index]["label"]
        column_label = column_label.replace(" ", "_").lower()
        if column and "v" in column:
            testcase[column_label] = column["v"]
        else:
            testcase[column_label] = "EMPTY"
        column_index += 1
    testcaseinfo.append(testcase)
print(testcaseinfo)