Created
November 1, 2019 02:38
-
-
Save rgreinho/d3fac33bcff8f45f4a8cd5cbc1be14f7 to your computer and use it in GitHub Desktop.
CRIS CRASH
This file contains 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 base64 | |
import os | |
from urllib import parse | |
import requests | |
def main(): | |
"""Define the main function of the app.""" | |
CRIS_URL = "https://cris.dot.state.tx.us" | |
# Create a request session. | |
session = requests.Session() | |
# Pre-login. | |
PRE_LOGIN_PAGE = parse.urljoin(CRIS_URL, "Shibboleth.sso/Login") | |
pre_login_params = { | |
"SAMLDS": "1", | |
"target": "cookie:1572558331_0a03", | |
"forceAuthn": "1", | |
"entityID": "https://cris.dot.state.tx.us/secure/txdotidp/shibboleth", | |
} | |
pre_login = session.get(PRE_LOGIN_PAGE, params=pre_login_params) | |
# Login. | |
# LOGIN_PAGE = parse.urljoin(CRIS_URL, "secure/txdotidp/profile/SAML2/Redirect/SSO?execution=e1s1") | |
LOGIN_PAGE = parse.urljoin(CRIS_URL, "Shibboleth.sso/SAML2/POST") | |
login_payload = { | |
"username": os.environ["ATD_CRIS_USER"], | |
"password": os.environ["ATD_CRIS_PASSWORD"], | |
} | |
login = session.post(LOGIN_PAGE, data=login_payload) | |
# Retrieve a PDF. | |
PDF_URL = "https://cris.dot.state.tx.us/secure/ImageServices/DisplayImageServlet" | |
params = {"target": base64.b64encode(b"CrashId=11156151")} | |
get_pdf = session.get(PDF_URL, params=params) | |
print(get_pdf.text) | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment