Commit 749df7a6 authored by Giuseppe Tropea's avatar Giuseppe Tropea
Browse files

added fetching from googlesheet

parent 3e1c844f
Loading
Loading
Loading
Loading
+28 −0
Original line number Diff line number Diff line
import requests
import json

site_request = requests.get("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")

site_response = str(site_request.content)

# remove from beginning up to the first {
json_response = site_response[site_response.index("{"):]
# remove from the last } till the end
json_response = json_response[:json_response.rindex("}")+1]

table = json.loads(json_response)
table = table["table"]
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
for row in table["rows"]:
    column_index = 0
    testcase = {}
    for column in row["c"]:
        column_label = table["cols"][column_index]["label"]
        column_label = column_label.replace(" ", "_").lower()
        testcase[column_label] = column["v"]
        column_index += 1
    testcaseinfo.append(testcase)
print(testcaseinfo)
 No newline at end of file
+5 −0
Original line number Diff line number Diff line
from eve import Eve
app = Eve()

if __name__ == '__main__':
    app.run()
 No newline at end of file
+16 −0
Original line number Diff line number Diff line
HATEOAS = False

googlesheetschema = {
    'googlesheet': {
        'seq_number': 'string',
        'required': True
    }
}

googlesheet = {
    # most global settings can be overridden at resource level
    'resource_methods': ['GET', 'POST'],
    'schema': googlesheetschema
}

DOMAIN = {'googlesheet': googlesheet}
 No newline at end of file