Skip to content

Commit

Permalink
Adjusted post/get for Endpoint v3
Browse files Browse the repository at this point in the history
  • Loading branch information
miballe committed Oct 15, 2024
1 parent 52da6da commit 53ae425
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
9 changes: 5 additions & 4 deletions src/factiva/analytics/snapshots/time_series.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class SnapshotTimeSeriesJobReponse(SnapshotBaseJobResponse):
"""

data : pd.DataFrame = None
download_link : str = None
errors : list[dict] = None
# Consider adding calculated values for start/end date and the number
# of records
Expand All @@ -43,7 +44,7 @@ def __repr__(self):

def __str__(self, detailed=True, prefix=' ├─', root_prefix=''):
ret_val = super().__str__(detailed, prefix, root_prefix)
ret_val += f"{prefix}data: {tools.print_property(self.data)}"
ret_val += f"{prefix}download_link: {tools.print_property(self.download_link)}"
if self.errors:
ret_val += f"\n{prefix.replace('├', '└')}errors: [{len(self.errors)}]"
err_list = [f"\n{prefix[0:-1]} |-{err['title']}: {err['detail']}" for err in self.errors]
Expand Down Expand Up @@ -284,8 +285,7 @@ def submit_job(self):

headers_dict = {
'user-key': self.user_key.key,
'Content-Type': 'application/json',
'X-API-VERSION': '2.0'
'Content-Type': 'application/json'
}

submit_url = f'{self.__JOB_BASE_URL}'
Expand Down Expand Up @@ -341,7 +341,8 @@ def get_job_response(self) -> bool:
self.job_response.job_state = response_data['data']['attributes']['current_state']
self.job_response.job_link = response_data['links']['self']
if self.job_response.job_state == const.API_JOB_DONE_STATE:
self.job_response.data = pd.DataFrame(response_data['data']['attributes']['results'])
# self.job_response.data = pd.DataFrame(response_data['data']['attributes']['results'])
self.job_response.download_link = response_data['data']['attributes']['download_link']
if 'errors' in response_data.keys():
self.job_response.errors = response_data['errors']
elif response.status_code == 404:
Expand Down
4 changes: 2 additions & 2 deletions test/snapshots/test_timeseries.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,6 @@ def test_job_envuser_envwhere():
assert len(sts.job_response.job_id) == 36
assert sts.job_response.job_link.startswith(const.API_HOST)
assert (sts.job_response.errors == None)
assert isinstance(sts.job_response.data, pd.DataFrame)
assert len(sts.job_response.data.columns) >= 2
# assert isinstance(sts.job_response.data, pd.DataFrame)
# assert len(sts.job_response.data.columns) >= 2

0 comments on commit 53ae425

Please sign in to comment.