diff --git a/examples/data/parse_sov_testfile.xlsx b/examples/data/parse_sov_testfile.xlsx new file mode 100644 index 0000000..cd9d586 Binary files /dev/null and b/examples/data/parse_sov_testfile.xlsx differ diff --git a/examples/pingdata_enhance.py b/examples/ping-data/pingdata_enhance.py similarity index 100% rename from examples/pingdata_enhance.py rename to examples/ping-data/pingdata_enhance.py diff --git a/examples/ping-extraction/parse_sov.py b/examples/ping-extraction/parse_sov.py new file mode 100644 index 0000000..6974b3c --- /dev/null +++ b/examples/ping-extraction/parse_sov.py @@ -0,0 +1,72 @@ +import time +from pathlib import Path +import requests +import os + +# authentication token that allows you to make requests to the API +API_KEY=os.environ.get('SOVFIXER_AUTH_TOKEN') +headers = {"Authorization": f"Token {API_KEY}"} + +# file being submitted +file_path = Path("parse_sov_testfile.xlsx") +files = {"file": ("parse_sov_testfile.xlsx", open(file_path, "rb"))} +# request options +payload = { + # what kind of document is being processed? SOV + "document_type": "SOV", + # how should the file be outputted? json, auditor + "output_formats": ["json", "auditor"], + # what data integrations should be used? Ping Geocoding, Ping Hazard + "integrations": ["PG", "PH"] +} + +# 1. API URL for Start SOV Parsing Job: https://api.sovfixer.com/api/v1/sov +start_job_url = f"https://api.sovfixer.com/api/v1/sov" +# API response +start_job_response = requests.post(start_job_url, data=payload, files=files, headers=headers) +# check response status and record the SOV ID +if start_job_response.status_code in (200, 201): + sovid = start_job_response.json()["id"] +else: + raise RuntimeError + +## ... + +# 2. API URL for Check SOV Parsing Job: https://api.sovfixer.com/api/v1/sov/{id} +check_job_url = f"https://api.sovfixer.com/api/v1/sov/{sovid}" +check_job_response = requests.get(check_job_url, headers=headers) +# ensure response is in a good state +assert check_job_response.status_code in (200, 201) +check_job_json = check_job_response.json() +# Poll every three seconds for job completion +while check_job_json["request"]["status"] not in ("COMPLETE", "FAILED"): + print(check_job_json) + print("Waiting 3 seconds to request again...") + time.sleep(3) + check_job_response = requests.get(check_job_url, headers=headers) + # ensure response is in a good state + assert check_job_response.status_code in (200, 201) + check_job_json = check_job_response.json() + +print(check_job_json) + +# record filenames and urls of the processed SOV outputs +outputs = [] +for output in check_job_json["result"]["outputs"]: + outputs.append( + { + "filename": output["filename"], + "url": output["url"] + } + ) + +## ... +# 3. API URL for Fetch Outputs of SOV Parsing Job: https://api.sovfixer.com/api/v1/sov/{id}/output/{filename} +for output in outputs: + fetch_outputs_response = requests.get(output["url"], headers=headers) + # ensure response is in a good state + assert fetch_outputs_response.status_code in (200, 201) + print(f"saving {output['filename']}") + with open(f"workflow_example_results/{output['filename']}", "wb") as outfile: + outfile.write(fetch_outputs_response.content) + print(f"saved {output['filename']}") \ No newline at end of file diff --git a/examples/sovfixer_fix_sov.py b/examples/ping-extraction/sovfixer_fix_sov.py similarity index 100% rename from examples/sovfixer_fix_sov.py rename to examples/ping-extraction/sovfixer_fix_sov.py diff --git a/examples/sovfixer_list_activity.py b/examples/ping-extraction/sovfixer_list_activity.py similarity index 100% rename from examples/sovfixer_list_activity.py rename to examples/ping-extraction/sovfixer_list_activity.py diff --git a/examples/sovfixer_reoutput_sov.py b/examples/ping-extraction/sovfixer_reoutput_sov.py similarity index 100% rename from examples/sovfixer_reoutput_sov.py rename to examples/ping-extraction/sovfixer_reoutput_sov.py diff --git a/examples/pingvision_activity.py b/examples/ping-vision/pingvision_activity.py similarity index 100% rename from examples/pingvision_activity.py rename to examples/ping-vision/pingvision_activity.py