Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Endpoint to download an Audit Template Report Submission and store in SEED #36

Merged
merged 2 commits into from
Nov 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 65 additions & 0 deletions pyseed/seed_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -1418,6 +1418,71 @@ def retrieve_at_building_and_update(self, audit_template_building_id: int, cycle

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
filename (str): filename to use to upload to SEED

Returns:
dict: Response from the SEED API
including the PDF file (if that format was requested)
"""

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

if response['status'] == 'success':
if report_format.lower() == 'pdf':
pdf_file = response['content']
if not filename:
filename = 'at_submission_report_' + str(audit_template_submission_id) + '.pdf'
files = [
('file', (filename, pdf_file)),
('file_type', (None, 1))
]
response2 = self.client.put(
None,
required_pk=False,
endpoint="properties_upload_inventory_document",
url_args={"PK": seed_id},
files=files
)
response2['pdf_report'] = pdf_file
else:
# assume XML
# now post to api/v3/properties/PK/update_with_buildingsync
xml_file = response['content']
if not filename:
filename = 'at_' + str(int(time.time() * 1000)) + '.xml'

files = [
('file', (filename, xml_file)),
('file_type', (None, 1))
]

response2 = self.client.put(
None,
required_pk=False,
endpoint="properties_update_with_buildingsync",
url_args={"PK": seed_id},
files=files,
cycle_id=cycle_id
)

return response2

def retrieve_portfolio_manager_property(self, username: str, password: str, pm_property_id: int, save_file_name: Path) -> dict:
"""Connect to portfolio manager and download an individual properties data in Excel format

Expand Down
6 changes: 6 additions & 0 deletions pyseed/seed_client_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,14 @@
# PUTs with replaceable keys:
'properties_update_with_buildingsync': 'api/v3/properties/PK/update_with_building_sync/',
'property_update_with_espm': 'api/v3/properties/PK/update_with_espm/',
'properties_upload_inventory_document': 'api/v3/properties/PK/upload_inventory_document',
# GETs with replaceable keys
'import_files_matching_results': '/api/v3/import_files/PK/matching_and_geocoding_results/',
'progress': '/api/v3/progress/PROGRESS_KEY/',
'properties_meters': '/api/v3/properties/PK/meters/',
'properties_meter_usage': '/api/v3/properties/PK/meter_usage/',
'audit_template_building_xml': '/api/v3/audit_template/PK/get_building_xml',
'audit_template_submission': '/api/v3/audit_template/PK/get_submission',
# GET & POST with replaceable keys
'properties_meters_reading': '/api/v3/properties/PK/meters/METER_PK/readings/',
}
Expand Down Expand Up @@ -216,6 +218,9 @@ def _check_response(self, response, *args, **kwargs):
elif 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' in response_content_types:
# spreadsheet response
error = False
elif 'application/pdf' in response_content_types:
# PDF report response
error = False
elif 'application/json' not in response_content_types:
# get as text
if not response.content:
Expand Down Expand Up @@ -477,6 +482,7 @@ def put(self, pk, endpoint=None, data_name=None, **kwargs):
data_name = _set_default(self, 'data_name', data_name, required=False)
url = add_pk(self.urls[endpoint], pk, required=kwargs.pop('required_pk', True), slash=True)
url = _replace_url_args(url, url_args)

response = super(UpdateMixin, self)._put(url=url, **kwargs)
self._check_response(response, **kwargs)
return self._get_result(response, data_name=data_name, **kwargs)
Expand Down