Skip to content

Instantly share code, notes, and snippets.

@gordonje
Created February 9, 2021 23:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gordonje/d3c41b961ecde4b20e64d5cc4ea27e2e to your computer and use it in GitHub Desktop.
Save gordonje/d3c41b961ecde4b20e64d5cc4ea27e2e to your computer and use it in GitHub Desktop.
import requests
from bs4 import BeautifulSoup
import json
url_stub = "https://results.mo.gov"
workbook_url = f"{url_stub}/t/COVID19/views/VaccinationsDashboard/Vaccinations"
workbook_params = {
':embed': 'y',
':showVizHome': 'no',
':host_url': 'https://results.mo.gov/',
':embed_code_version': 3,
':tabs': 'no',
':toolbar': 'yes',
':showAppBanner': False,
':display_spinner': 'no',
':loadOrderID': 0
}
with requests.Session() as s:
get_resp = s.get(workbook_url, params=workbook_params)
soup = BeautifulSoup(get_resp.text, "html.parser")
tableauData = json.loads(soup.find("textarea", {"id": "tsConfigContainer"}).text)
dataUrl = f'{url_stub}{tableauData["vizql_root"]}/bootstrapSession/sessions/{tableauData["sessionid"]}'
form_data = {"sheet_id": tableauData["sheetId"]}
post_resp = s.post(dataUrl, data=form_data)
doses_by_day_url = f"https://results.mo.gov/vizql/t/COVID19/w/VaccinationsDashboard/v/Vaccinations/viewData/sessions/{tableauData['sessionid']}/views/3135269236547538553_15812068501332622347"
worksheet_params = {
'maxrows': ['200'],
'viz': ['{"worksheet":"By Date","dashboard":"Vaccinations"}']
}
doses_by_day_url = f"https://results.mo.gov/vizql/t/COVID19/w/VaccinationsDashboard/v/Vaccinations/vudcsv/sessions/{tableauData['sessionid']}/views/3135269236547538553_15812068501332622347"
worksheet_params = {'summary': True}
data = s.get(doses_by_day_url, params=workbook_params)
print(data.text)
@gordonje
Copy link
Author

gordonje commented Feb 9, 2021

My (unsuccessful) attempt to implement this solution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment