Created
February 9, 2021 23:01
-
-
Save gordonje/d3c41b961ecde4b20e64d5cc4ea27e2e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
My (unsuccessful) attempt to implement this solution.