-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Labels
documentationImprovements or additions to documentationImprovements or additions to documentationinformationCode examples as-used in the docsCode examples as-used in the docs
Description
def get_pdf_images(
pro: str,
which: str,
scac_or_carrier_id: Union[str, int] = "LN",
test_output: bool = False,
):
full_url = (
url.format(
method=which,
api_key=get_api_key(scac_or_carrier_id),
pro=pro,
scac=scac_or_carrier_id,
) # providing dl=1 flag ensures we get content-disposition response header
+ "&dl=1"
)
with urllib.request.urlopen(full_url) as resp:
rr = resp.read()
filename_header = resp.headers["content-disposition"]
if not filename_header:
return json.loads(rr.decode())
filename = filename_header.partition("=")[-1].strip('"')
if test_output:
assert filename.endswith(".pdf"), (
"File should be a pdf, not a: " + filename.rpartition(".")[-1]
)
assert b"PDF" in rr[:4], "File does not seem to be a pdf"
# should be <pro>_lading.pdf or <pro>_proof.pdf
with open(filename, "wb") as out:
out.write(rr)
return filename
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
documentationImprovements or additions to documentationImprovements or additions to documentationinformationCode examples as-used in the docsCode examples as-used in the docs