Skip to content

Commit

Permalink
new_webservices. Changed supported agencies and corrected SDMX API v2…
Browse files Browse the repository at this point in the history
… method. Using OECD v1 method on v2 API due to not implemented when querying for all dataflows.
  • Loading branch information
javihern98 committed Sep 25, 2023
1 parent b7539dd commit fc6c268
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 5 deletions.
6 changes: 5 additions & 1 deletion sdmxthon/api/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,4 +137,8 @@ def get_supported_agencies():
'BIS': webservices.BisWs,
'ECB': webservices.EcbWs,
'ESTAT': webservices.EuroStatWs,
'ILO': webservices.IloWs}
'ILO': webservices.IloWs,
'OECD': webservices.OecdWs,
'OECDv2': webservices.OecdWs2,
'UNICEF': webservices.UnicefWs,
}
6 changes: 4 additions & 2 deletions sdmxthon/webservices/query_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,9 @@ def get_data_flows(self, agency_id, resources=None,
version=None, references=None, detail=None) -> str:
resources = resources if resources else "all"
version = version if version else "latest"
agency_id = agency_id if agency_id else "all"

base_query = f"dataflow/{agency_id}/{resources}/{version}"
base_query = f"/structure/dataflow/{agency_id}/{resources}/{version}"

params = ""
if references:
Expand All @@ -117,7 +118,8 @@ def get_data(self, dataflow_id, provider=None, version=None,
first_n_observations=None, last_n_observations=None,
dimension_at_observation=None,
detail=None, include_history=None):
base_query = f"/data/dataflow/{provider}/{dataflow_id}/{version}"
base_query = f"/data/dataflow/{provider}/{dataflow_id}"
base_query += f"/{version}" if version else ""

base_query += f"/{key}" if key else ""

Expand Down
6 changes: 5 additions & 1 deletion sdmxthon/webservices/webservices.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class SdmxWebServiceConnection(ABC):
def get_all_dataflows(self):
"""Returns a list of all dataflows"""
url = (f"{self.ENTRY_POINT}"
f"{self.WS_IMPLEMENTATION.get_data_flows(self.AGENCY_ID)}")
f"{self.WS_IMPLEMENTATION.get_data_flows()}")
message = read_xml(url, validate=False)
dataflows = message['Dataflows'].values()
list_dataflows = []
Expand Down Expand Up @@ -183,6 +183,10 @@ class OecdWs2(SdmxWebServiceConnection):
ENTRY_POINT = 'https://sdmx.oecd.org/public/rest/v2'
WS_IMPLEMENTATION = query_builder.QueryBuilder(query_builder.SdmxWs2p0())

def get_all_dataflows(self):
"""Not supported by v2, goes to v1"""
return OecdWs().get_all_dataflows()


class UnicefWs(SdmxWebServiceConnection):
"""Implements the connection to the ILO SDMX web service"""
Expand Down
4 changes: 3 additions & 1 deletion testApi.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ def main():
dataflow_id = 'BRAZIL_CO'
agency_id = 'BRAZIL_CO'

print(ws.get_data_url(dataflow_id, last_n_observations=1))
print(ws.get_all_dataflows())

# print(ws.get_data_url(dataflow_id, last_n_observations=1))
# print(ws.get_data_flow(dataflow_id, agency_id=agency_id, references='descendants').content)
# data = ws.get_data(dataflow_id, provider=agency_id, version=version,
# last_n_observations=1)
Expand Down

0 comments on commit fc6c268

Please sign in to comment.