bertrandmartel / tableau-scraping

Tableau scraper python library. R and Python scripts to scrape data from Tableau viz
MIT License
131 stars 21 forks source link

Can't set a Parameter if not listed in getParameters() #49

Closed djay closed 2 years ago

djay commented 2 years ago

I wrote this code to get around it but would be better if it was flag or something?

def force_setParameter(wb, parameterName, value):
    "Allow for setting a parameter even if it's not present in getParameters"
    scraper = wb._scraper
    tableauscraper.api.delayExecution(scraper)
    payload = (
        ("fieldCaption", (None, parameterName)),
        ("valueString", (None, value)),
    )
    r = scraper.session.post(
        f'{scraper.host}{scraper.tableauData["vizql_root"]}/sessions/{scraper.tableauData["sessionid"]}/commands/tabdoc/set-parameter-value',
        files=payload,
        verify=scraper.verify
    )
    scraper.lastActionTime = time.time()
    if r.status_code >= 400:
        raise requests.exceptions.RequestException(r.content)
    resp = r.json()

    wb.updateFullData(resp)
    return tableauscraper.dashboard.getWorksheetsCmdResponse(scraper, resp)
bertrandmartel commented 2 years ago

@djay In the next release, you can the input parameter value:

wb = wb.setParameter(inputName=None, value="Ligue 1",
                    inputParameter="[Parameters].[P.League (copy)_1642969456470679625]")

which is equivalent to:

wb = wb.setParameter("P.League 2", "Ligue 1")

The input name is different from the parameter name in the model. In the query the parameter name usually looks like [Parameters].[something]

djay commented 2 years ago

@bertrandmartel thats a bit confusing IHO. is inputParameter meant to be an override of the inputName or value? I think you're saying its an override of the inputName since that is set to None? but its in another format... so how am I supposed to work out what that special format is? Wouldn't a validate=False be more intuitive?