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

No data dictionary present in response #38

Closed az-data-guru closed 3 years ago

az-data-guru commented 3 years ago

Hey Bertrand,

AZDHS just recently changed their dashboards and the testing tableau now requires that I take two actions on it to get to the data I need. When I try that I get a warning that no data dictonary present in response.

This could just be my weakness with python.

Thanks for the help.

from tableauscraper import TableauScraper as TS
import pandas as pd
import time
import numpy as np

url = 'https://tableau.azdhs.gov/views/ELR/TestsConducted?%3Aembed=y&'

# In[]:

data_list = []
value = 0
df = pd.DataFrame( columns = ["date", "tests"])
sheetName = "P1 - Tests by Day W/ % Positivity (Both)"

ts = TS()
ts.loads(url)
dashboard = ts.getWorkbook().getWorksheet('Date Range Filter').select("Time Frame", "All Time")

d = dashboard.getWorksheet(sheetName).levelDrill(drillDown=False, position=1)
az-data-guru commented 3 years ago

There seems to be an issue with the drill down itself. I ran the template and it through a KeyError.

from tableauscraper import TableauScraper as TS

url = 'https://tableau.azdhs.gov/views/ELR/TestsConducted?%3Aembed=y&'
ts = TS()
ts.loads(url)
wb = ts.getWorkbook()

sheetName = "P1 - Tests by Day W/ % Positivity (Both)"

drillDown1 = wb.getWorksheet(sheetName).levelDrill(drillDown=True, position=1)
drillDown2 = drillDown1.getWorksheet(sheetName).levelDrill(drillDown=True, position=1)
drillDown3 = drillDown2.getWorksheet(sheetName).levelDrill(drillDown=True, position=1)

print(drillDown1.getWorksheet(sheetName).data)
print(drillDown2.getWorksheet(sheetName).data)
print(drillDown3.getWorksheet(sheetName).data)
bertrandmartel commented 3 years ago

@az-data-guru You can get the correct data by dropping position=1 since it seems the position is now set to 0 (the default)

bertrandmartel commented 3 years ago

I've fixed the key error in any case

The following gets the data:

from tableauscraper import TableauScraper as TS

url = 'https://tableau.azdhs.gov/views/ELR/TestsConducted?%3Aembed=y&'
ts = TS()
ts.loads(url)
wb = ts.getWorkbook()

sheetName = "P1 - Tests by Day W/ % Positivity (Both)"

drillDown1 = wb.getWorksheet(sheetName).levelDrill(drillDown=True)
print(drillDown1.getWorksheet(sheetName).data["MONTH(Collection Date)-alias"])

drillDown2 = drillDown1.getWorksheet(sheetName).levelDrill(drillDown=True)
print(drillDown2.getWorksheet(
    sheetName).data["QUARTER(Collection Date)-alias"])

drillDown3 = drillDown2.getWorksheet(sheetName).levelDrill(drillDown=True)
print(drillDown3.getWorksheet(sheetName).data["YEAR(Collection Date)-alias"])

The problem is that the workbook doesn't retain the data so you can get the data between calls, you can get around this for now. I'm working on it

bertrandmartel commented 3 years ago

@az-data-guru I've fixed the getWorksheet and getWorksheets in the latest release.

Also since last week, the zones are stored in the scraper object, it means than you don't have to pass the last workbook to the next call anymore, since it's shared

For example:

from tableauscraper import TableauScraper as TS

url = 'https://tableau.azdhs.gov/views/ELR/TestsConducted?%3Aembed=y&'
ts = TS()
ts.loads(url)
sheetName = "P1 - Tests by Day W/ % Positivity (Both)"
ws = ts.getWorkbook().getWorksheet(sheetName)

drillDown1 = ws.levelDrill(drillDown=True)
drillDown2 = ws.levelDrill(drillDown=True)
drillDown3 = ws.levelDrill(drillDown=True)

print(drillDown1.getWorksheet(sheetName).data)
print(drillDown2.getWorksheet(sheetName).data)
print(drillDown3.getWorksheet(sheetName).data)

https://replit.com/@bertrandmartel/TableauCovidAZDHSTests