Skip to content

Commit

Permalink
add new method to get AT submission metadata (#39)
Browse files Browse the repository at this point in the history
  • Loading branch information
kflemin authored Jan 16, 2024
1 parent 43a793b commit 8900c11
Showing 1 changed file with 25 additions and 3 deletions.
28 changes: 25 additions & 3 deletions pyseed/seed_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -1427,14 +1427,35 @@ def retrieve_at_building_and_update(self, audit_template_building_id: int, cycle

return response

def retrieve_at_submission_metadata(self, audit_template_submission_id: int) -> dict:
"""Connect to audit template and retrieve audit report json (metadata only) by submission ID
Args:
audit_template_submission_id (int): ID of the AT submission report (different than building ID)
Returns:
dict: Response from the SEED API
"""

# api/v3/audit_template/pk/get_submission
response = self.client.get(
None,
required_pk=False,
endpoint="audit_template_submission",
url_args={"PK": audit_template_submission_id},
report_format='json'
)

return response

def retrieve_at_submission_and_update(self, audit_template_submission_id: int, cycle_id: int, seed_id: int, report_format: str = 'pdf', filename: str = None) -> dict:
"""Connect to audit template and retrieve audit report by submission ID
Args:
audit_template_submission_id (int): ID of the AT submission report (different than building ID)
cycle_id (int): Cycle ID in SEED (needed for XML but not actually for PDF)
seed_id (int): PropertyView ID in SEED
file_format (str): pdf or xml report, defaults to pdf
file_format (str): pdf, or xml report, defaults to pdf
filename (str): filename to use to upload to SEED
Returns:
Expand All @@ -1443,7 +1464,7 @@ def retrieve_at_submission_and_update(self, audit_template_submission_id: int, c
"""

# api/v3/audit_template/pk/get_submission
# accepts pdf or xml
# accepts pdf, xml
response = self.client.get(
None,
required_pk=False,
Expand All @@ -1454,6 +1475,7 @@ def retrieve_at_submission_and_update(self, audit_template_submission_id: int, c

if response['status'] == 'success':
if report_format.lower() == 'pdf':
# for PDF, store pdf report as inventory document
pdf_file = response['content']
if not filename:
filename = 'at_submission_report_' + str(audit_template_submission_id) + '.pdf'
Expand All @@ -1470,7 +1492,7 @@ def retrieve_at_submission_and_update(self, audit_template_submission_id: int, c
)
response2['pdf_report'] = pdf_file
else:
# assume XML
# assume XML. for XML, update property with BuildingSync
# now post to api/v3/properties/PK/update_with_buildingsync
xml_file = response['content']
if not filename:
Expand Down

0 comments on commit 8900c11

Please sign in to comment.