Ejemplo n.º 1
0
def get(TS, data, info, logger):
    output = []
    worksheets = utils.selectWorksheet(data, logger)

    for worksheet in worksheets:
        df = getWorksheet(TS, data, info, worksheet)
        output.append(df)

    return TableauDashboard(scraper=TS,
                            originalData=data,
                            originalInfo=info,
                            data=output)
Ejemplo n.º 2
0
def test_selectWorksheet(monkeypatch):
    logger = logging.getLogger("tableauScraper")
    # all worksheet
    monkeypatch.setattr("builtins.input", lambda _: "")
    worksheets = utils.selectWorksheet(data, logger)
    assert len(worksheets) == 2
    assert worksheets == ["[WORKSHEET1]", "[WORKSHEET2]"]

    # select 1 worksheet
    monkeypatch.setattr("builtins.input", lambda _: "0")
    worksheets = utils.selectWorksheet(data, logger)
    assert len(worksheets) == 1
    assert worksheets == ["[WORKSHEET1]"]

    # return 1 element
    monkeypatch.setattr("builtins.input", lambda _: "")
    pytest.raises(Exception, utils.selectWorksheet, data, logger, single=True)
    monkeypatch.setattr("builtins.input", lambda _: "0")
    assert len(worksheets) == 1
    assert worksheets == ["[WORKSHEET1]"]

    # no worksheet
    worksheets = utils.selectWorksheet(noWorksheet, logger)
    assert len(worksheets) == 0
Ejemplo n.º 3
0
def get(TS, data, info, logger):
    worksheets = utils.selectWorksheet(data, logger, single=True)
    if len(worksheets) == 0:
        return TableauDashboard(scraper=TS,
                                originalData=data,
                                originalInfo=info,
                                data=[])
    selectedWorksheet = worksheets[0]

    presModel = utils.getPresModelVizData(data)
    result = utils.getIndicesInfo(presModel,
                                  selectedWorksheet,
                                  noSelectFilter=False)

    for idx, t in enumerate(result):
        logger.info(f"[{idx}] {t['fieldCaption']}")

    selected = input(f"select field by index : ")

    if (selected is None) or (selected == ""):
        raise (Exception("you must select at least one field"))
    field = result[int(selected)]
    logger.info(f"you have selected {field['fieldCaption']}")

    dataFull = utils.getDataFull(presModel)
    frameData = utils.getData(dataFull, [field])
    frameDataKeys = list(frameData.keys())

    if len(frameDataKeys) == 0:
        raise (Exception("no data extracted"))

    data = frameData[frameDataKeys[0]]
    for idx, t in enumerate(data):
        logger.info(f"[{idx}] {t}")

    selected = input(f"select value by index : ")
    if (selected is None) or (selected == ""):
        raise (Exception("you must select at least one value"))
    value = data[int(selected)]
    logger.info(f"you have selected {value}")

    r = api.select(TS, selectedWorksheet, [int(selected) + 1])
    return dashboard.getCmdResponse(TS, r, logger)