Skip to content

Commit

Permalink
Add p-code check
Browse files Browse the repository at this point in the history
  • Loading branch information
b-j-mills committed Feb 4, 2025
1 parent b76f50c commit 53ab7ec
Show file tree
Hide file tree
Showing 9 changed files with 40,249 additions and 6,580 deletions.
2 changes: 1 addition & 1 deletion .config/ruff.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
line-length = 79
line-length = 90
exclude = ["_version.py"]

[lint]
Expand Down
110 changes: 57 additions & 53 deletions src/hdx/scraper/dtm/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from os.path import dirname, expanduser, join

from hdx.api.configuration import Configuration
from hdx.api.utilities.hdx_error_handler import HDXErrorHandler
from hdx.facades.infer_arguments import facade
from hdx.utilities.downloader import Download
from hdx.utilities.path import (
Expand All @@ -29,79 +30,82 @@
def main(
save: bool = True,
use_saved: bool = False,
err_to_hdx: bool = False,
) -> None:
"""Generate datasets and create them in HDX
Args:
save (bool): Save downloaded data. Defaults to True.
use_saved (bool): Use saved data. Defaults to False.
err_to_hdx (bool): Whether to write any errors to HDX metadata. Defaults to False.
Returns:
None
"""
with wheretostart_tempdir_batch(folder=_USER_AGENT_LOOKUP) as info:
temp_dir = info["folder"]
with Download() as downloader:
configuration = Configuration.read()
retriever = Retrieve(
downloader=downloader,
fallback_dir=temp_dir,
saved_dir=_SAVED_DATA_DIR,
temp_dir=temp_dir,
save=save,
use_saved=use_saved,
)
dtm = Dtm(
configuration=configuration,
retriever=retriever,
temp_dir=temp_dir,
)

countries_list = dtm.get_countries()
operation_status = dtm.get_operation_status()
for countries in [
countries_list,
*[[x] for x in countries_list],
]:
dataset = dtm.generate_dataset(
countries=countries, operation_status=operation_status
with HDXErrorHandler(write_to_hdx=err_to_hdx) as error_handler:
with wheretostart_tempdir_batch(folder=_USER_AGENT_LOOKUP) as info:
temp_dir = info["folder"]
with Download() as downloader:
configuration = Configuration.read()
retriever = Retrieve(
downloader=downloader,
fallback_dir=temp_dir,
saved_dir=_SAVED_DATA_DIR,
temp_dir=temp_dir,
save=save,
use_saved=use_saved,
)
dataset.update_from_yaml(
path=join(
dirname(__file__), "config", "hdx_dataset_static.yaml"
)
dtm = Dtm(
configuration=configuration,
retriever=retriever,
temp_dir=temp_dir,
error_handler=error_handler,
)
if len(countries) > 1:
dataset.generate_quickcharts(
resource=1,
path=script_dir_plus_file(
join("config", "hdx_resource_view_static.yaml"),
main,
),

countries_list = dtm.get_countries()
operation_status = dtm.get_operation_status()
for countries in [
countries_list,
*[[x] for x in countries_list],
]:
dataset = dtm.generate_dataset(
countries=countries, operation_status=operation_status
)
dataset.create_in_hdx(
remove_additional_resources=True,
match_resource_order=False,
hxl_update=False,
updated_by_script=_UPDATED_BY_SCRIPT,
batch=info["batch"],
)
if len(countries) > 1:
hapi_dataset = dtm.generate_hapi_dataset(dataset["name"])
hapi_dataset.update_from_yaml(
path=join(
dirname(__file__),
"config",
"hdx_hapi_dataset_static.yaml",
)
dataset.update_from_yaml(
path=join(dirname(__file__), "config", "hdx_dataset_static.yaml")
)
hapi_dataset.create_in_hdx(
if len(countries) > 1:
dataset.generate_quickcharts(
resource=1,
path=script_dir_plus_file(
join("config", "hdx_resource_view_static.yaml"),
main,
),
)
dataset.create_in_hdx(
remove_additional_resources=True,
match_resource_order=False,
hxl_update=False,
updated_by_script=_UPDATED_BY_SCRIPT,
batch=info["batch"],
)
if len(countries) > 1:
hapi_dataset = dtm.generate_hapi_dataset(dataset["name"])
hapi_dataset.update_from_yaml(
path=join(
dirname(__file__),
"config",
"hdx_hapi_dataset_static.yaml",
)
)
hapi_dataset.create_in_hdx(
remove_additional_resources=True,
match_resource_order=False,
hxl_update=False,
updated_by_script=_UPDATED_BY_SCRIPT,
batch=info["batch"],
)
logger.info("HDX Scraper DTM pipeline completed!")


if __name__ == "__main__":
Expand Down
2 changes: 1 addition & 1 deletion src/hdx/scraper/dtm/config/hdx_hapi_dataset_static.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ license_other: >
as well as the following credit line: Source: “International Organization for
Migration (IOM), Displacement Tracking Matrix (DTM)”.
methodology: Registry
caveats: None
caveats: ""
dataset_source: International Organization for Migration (IOM)
package_creator: HDX Data Systems Team
private: False
Expand Down
6 changes: 4 additions & 2 deletions src/hdx/scraper/dtm/config/project_configuration.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,12 @@ hapi_hxl_tags:
location_code: "#country+code"
has_hrp: "#meta+has_hrp"
in_gho: "#meta+in_gho"
admin1_name: "#adm1+name"
provider_admin1_name: "#adm1+name+provider"
provider_admin2_name: "#adm2+name+provider"
admin1_code: "#adm1+code"
admin2_name: "#adm2+name"
admin1_name: "#adm1+name"
admin2_code: "#adm2+code"
admin2_name: "#adm2+name"
admin_level: "#adm+level"
operation: "#operation+name"
assessment_type: "#assessment+type"
Expand Down
Loading

0 comments on commit 53ab7ec

Please sign in to comment.