Skip to content

Commit 606bd3c

Browse files
Merge pull request #27 from OpenDataServices/post_special_case
Add functionality for downloading dataset via post request
2 parents 14f413f + 2ab2014 commit 606bd3c

File tree

3 files changed

+12
-5
lines changed

3 files changed

+12
-5
lines changed

oc4ids_datastore_pipeline/pipeline.py

+10-3
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,17 @@ def __init__(self, errors_count: int, errors: list[str]):
3636
super().__init__(message)
3737

3838

39-
def download_json(url: str) -> Any:
39+
def download_json(dataset_id: str, url: str) -> Any:
4040
logger.info(f"Downloading json from {url}")
4141
try:
42-
r = requests.get(url)
42+
if dataset_id == "malawi_cost_malawi":
43+
payload = {
44+
"start_date": "2010-01-01",
45+
"end_date": datetime.datetime.today().strftime("%Y-%m-%d"),
46+
}
47+
r = requests.post(url, json=payload)
48+
else:
49+
r = requests.get(url)
4350
r.raise_for_status()
4451
response_size = len(r.content)
4552
logger.info(f"Downloaded {url} ({response_size} bytes)")
@@ -130,7 +137,7 @@ def save_dataset_metadata(
130137

131138
def process_dataset(dataset_id: str, source_url: str) -> None:
132139
logger.info(f"Processing dataset {dataset_id}")
133-
json_data = download_json(source_url)
140+
json_data = download_json(dataset_id, source_url)
134141
validate_json(dataset_id, json_data)
135142
json_path = write_json_to_file(
136143
file_name=f"data/{dataset_id}/{dataset_id}.json",

pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ build-backend = "flit_core.buildapi"
55
[project]
66
name = "oc4ids-datastore-pipeline"
77
description = "OC4IDS Datastore Pipeline"
8-
version = "0.3.0"
8+
version = "0.4.0"
99
readme = "README.md"
1010
dependencies = [
1111
"alembic",

tests/test_pipeline.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def test_download_json_raises_failure_exception(mocker: MockerFixture) -> None:
2222
patch_get.side_effect = Exception("Mocked exception")
2323

2424
with pytest.raises(ProcessDatasetError) as exc_info:
25-
download_json(url="https://test_dataset.json")
25+
download_json(dataset_id="test_dataset", url="https://test_dataset.json")
2626

2727
assert "Download failed" in str(exc_info.value)
2828
assert "Mocked exception" in str(exc_info.value)

0 commit comments

Comments
 (0)