hdx-python-api 6.6.3__tar.gz → 6.6.5__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {hdx_python_api-6.6.3 → hdx_python_api-6.6.5}/.github/workflows/publish.yaml +11 -14
- hdx_python_api-6.6.5/.github/workflows/run-python-tests.yaml +52 -0
- {hdx_python_api-6.6.3 → hdx_python_api-6.6.5}/.pre-commit-config.yaml +10 -9
- {hdx_python_api-6.6.3 → hdx_python_api-6.6.5}/PKG-INFO +88 -13
- hdx_python_api-6.6.5/README.md +100 -0
- {hdx_python_api-6.6.3 → hdx_python_api-6.6.5}/documentation/index.md +2 -0
- hdx_python_api-6.6.5/pyproject.toml +148 -0
- {hdx_python_api-6.6.3 → hdx_python_api-6.6.5}/src/hdx/api/_version.py +2 -2
- hdx_python_api-6.6.5/src/hdx/api/utilities/url_utils.py +135 -0
- {hdx_python_api-6.6.3 → hdx_python_api-6.6.5}/src/hdx/data/dataset.py +15 -34
- {hdx_python_api-6.6.3 → hdx_python_api-6.6.5}/src/hdx/data/resource.py +3 -10
- {hdx_python_api-6.6.3 → hdx_python_api-6.6.5}/tests/hdx/api/utilities/test_hdx_state.py +2 -3
- hdx_python_api-6.6.5/tests/hdx/api/utilities/test_url_utils.py +195 -0
- {hdx_python_api-6.6.3 → hdx_python_api-6.6.5}/tests/hdx/data/test_dataset_add_hapi_error.py +1 -2
- {hdx_python_api-6.6.3 → hdx_python_api-6.6.5}/tests/hdx/data/test_dataset_core.py +6 -7
- {hdx_python_api-6.6.3 → hdx_python_api-6.6.5}/tests/hdx/data/test_dataset_noncore.py +6 -61
- {hdx_python_api-6.6.3 → hdx_python_api-6.6.5}/tests/hdx/data/test_organization.py +2 -3
- {hdx_python_api-6.6.3 → hdx_python_api-6.6.5}/tests/hdx/data/test_resource.py +2 -3
- {hdx_python_api-6.6.3 → hdx_python_api-6.6.5}/tests/hdx/data/test_resource_view.py +1 -2
- {hdx_python_api-6.6.3 → hdx_python_api-6.6.5}/tests/hdx/data/test_showcase.py +2 -3
- {hdx_python_api-6.6.3 → hdx_python_api-6.6.5}/tests/hdx/data/test_user.py +1 -2
- {hdx_python_api-6.6.3 → hdx_python_api-6.6.5}/tests/hdx/data/test_vocabulary.py +1 -2
- {hdx_python_api-6.6.3 → hdx_python_api-6.6.5}/tests/hdx/facades/test_infer_arguments.py +1 -2
- {hdx_python_api-6.6.3 → hdx_python_api-6.6.5}/tests/hdx/facades/test_keyword_arguments.py +1 -2
- {hdx_python_api-6.6.3 → hdx_python_api-6.6.5}/tests/hdx/facades/test_simple.py +1 -2
- hdx_python_api-6.6.5/uv.lock +2148 -0
- {hdx_python_api-6.6.3 → hdx_python_api-6.6.5}/workingexample/run.py +1 -2
- hdx_python_api-6.6.3/.coveragerc +0 -17
- hdx_python_api-6.6.3/.github/workflows/run-python-tests.yaml +0 -60
- hdx_python_api-6.6.3/CONTRIBUTING.md +0 -68
- hdx_python_api-6.6.3/README.md +0 -16
- hdx_python_api-6.6.3/hatch.toml +0 -37
- hdx_python_api-6.6.3/pyproject.toml +0 -59
- hdx_python_api-6.6.3/pytest.ini +0 -4
- hdx_python_api-6.6.3/requirements.txt +0 -210
- hdx_python_api-6.6.3/ruff.toml +0 -10
- hdx_python_api-6.6.3/src/hdx/api/utilities/dataset_title_helper.py +0 -254
- hdx_python_api-6.6.3/tests/hdx/api/utilities/test_dataset_title_helper.py +0 -301
- {hdx_python_api-6.6.3 → hdx_python_api-6.6.5}/.gitignore +0 -0
- {hdx_python_api-6.6.3 → hdx_python_api-6.6.5}/LICENSE +0 -0
- {hdx_python_api-6.6.3 → hdx_python_api-6.6.5}/documentation/.readthedocs.yaml +0 -0
- {hdx_python_api-6.6.3 → hdx_python_api-6.6.5}/documentation/mkdocs.yaml +0 -0
- {hdx_python_api-6.6.3 → hdx_python_api-6.6.5}/src/hdx/api/__init__.py +0 -0
- {hdx_python_api-6.6.3 → hdx_python_api-6.6.5}/src/hdx/api/configuration.py +0 -0
- {hdx_python_api-6.6.3 → hdx_python_api-6.6.5}/src/hdx/api/hdx_base_configuration.yaml +0 -0
- {hdx_python_api-6.6.3 → hdx_python_api-6.6.5}/src/hdx/api/locations.py +0 -0
- {hdx_python_api-6.6.3 → hdx_python_api-6.6.5}/src/hdx/api/remotehdx.py +0 -0
- {hdx_python_api-6.6.3 → hdx_python_api-6.6.5}/src/hdx/api/utilities/__init__.py +0 -0
- {hdx_python_api-6.6.3 → hdx_python_api-6.6.5}/src/hdx/api/utilities/date_helper.py +0 -0
- {hdx_python_api-6.6.3 → hdx_python_api-6.6.5}/src/hdx/api/utilities/filestore_helper.py +0 -0
- {hdx_python_api-6.6.3 → hdx_python_api-6.6.5}/src/hdx/api/utilities/hdx_error_handler.py +0 -0
- {hdx_python_api-6.6.3 → hdx_python_api-6.6.5}/src/hdx/api/utilities/hdx_state.py +0 -0
- {hdx_python_api-6.6.3 → hdx_python_api-6.6.5}/src/hdx/data/__init__.py +0 -0
- {hdx_python_api-6.6.3 → hdx_python_api-6.6.5}/src/hdx/data/hdx_datasource_topline.yaml +0 -0
- {hdx_python_api-6.6.3 → hdx_python_api-6.6.5}/src/hdx/data/hdxobject.py +0 -0
- {hdx_python_api-6.6.3 → hdx_python_api-6.6.5}/src/hdx/data/indicator_resource_view_template.yaml +0 -0
- {hdx_python_api-6.6.3 → hdx_python_api-6.6.5}/src/hdx/data/organization.py +0 -0
- {hdx_python_api-6.6.3 → hdx_python_api-6.6.5}/src/hdx/data/resource_matcher.py +0 -0
- {hdx_python_api-6.6.3 → hdx_python_api-6.6.5}/src/hdx/data/resource_view.py +0 -0
- {hdx_python_api-6.6.3 → hdx_python_api-6.6.5}/src/hdx/data/showcase.py +0 -0
- {hdx_python_api-6.6.3 → hdx_python_api-6.6.5}/src/hdx/data/user.py +0 -0
- {hdx_python_api-6.6.3 → hdx_python_api-6.6.5}/src/hdx/data/vocabulary.py +0 -0
- {hdx_python_api-6.6.3 → hdx_python_api-6.6.5}/src/hdx/facades/__init__.py +0 -0
- {hdx_python_api-6.6.3 → hdx_python_api-6.6.5}/src/hdx/facades/infer_arguments.py +0 -0
- {hdx_python_api-6.6.3 → hdx_python_api-6.6.5}/src/hdx/facades/keyword_arguments.py +0 -0
- {hdx_python_api-6.6.3 → hdx_python_api-6.6.5}/src/hdx/facades/simple.py +0 -0
- {hdx_python_api-6.6.3 → hdx_python_api-6.6.5}/tests/__init__.py +0 -0
- {hdx_python_api-6.6.3 → hdx_python_api-6.6.5}/tests/fixtures/Accepted_Tags.csv +0 -0
- {hdx_python_api-6.6.3 → hdx_python_api-6.6.5}/tests/fixtures/CKAN/hdx_dataset_static.yaml +0 -0
- {hdx_python_api-6.6.3 → hdx_python_api-6.6.5}/tests/fixtures/Tag_Mapping.csv +0 -0
- {hdx_python_api-6.6.3 → hdx_python_api-6.6.5}/tests/fixtures/Tag_Mapping_ChainRuleError.csv +0 -0
- {hdx_python_api-6.6.3 → hdx_python_api-6.6.5}/tests/fixtures/config/empty.yaml +0 -0
- {hdx_python_api-6.6.3 → hdx_python_api-6.6.5}/tests/fixtures/config/hdx_base_config.json +0 -0
- {hdx_python_api-6.6.3 → hdx_python_api-6.6.5}/tests/fixtures/config/hdx_base_config.yaml +0 -0
- {hdx_python_api-6.6.3 → hdx_python_api-6.6.5}/tests/fixtures/config/hdx_config.json +0 -0
- {hdx_python_api-6.6.3 → hdx_python_api-6.6.5}/tests/fixtures/config/hdx_config.yaml +0 -0
- {hdx_python_api-6.6.3 → hdx_python_api-6.6.5}/tests/fixtures/config/hdx_dataset_static.json +0 -0
- {hdx_python_api-6.6.3 → hdx_python_api-6.6.5}/tests/fixtures/config/hdx_dataset_static.yaml +0 -0
- {hdx_python_api-6.6.3 → hdx_python_api-6.6.5}/tests/fixtures/config/hdx_datasource_topline.json +0 -0
- {hdx_python_api-6.6.3 → hdx_python_api-6.6.5}/tests/fixtures/config/hdx_datasource_topline.yaml +0 -0
- {hdx_python_api-6.6.3 → hdx_python_api-6.6.5}/tests/fixtures/config/hdx_email_configuration.json +0 -0
- {hdx_python_api-6.6.3 → hdx_python_api-6.6.5}/tests/fixtures/config/hdx_email_configuration.yaml +0 -0
- {hdx_python_api-6.6.3 → hdx_python_api-6.6.5}/tests/fixtures/config/hdx_missing_site_config.json +0 -0
- {hdx_python_api-6.6.3 → hdx_python_api-6.6.5}/tests/fixtures/config/hdx_organization_static.json +0 -0
- {hdx_python_api-6.6.3 → hdx_python_api-6.6.5}/tests/fixtures/config/hdx_organization_static.yaml +0 -0
- {hdx_python_api-6.6.3 → hdx_python_api-6.6.5}/tests/fixtures/config/hdx_resource_static.json +0 -0
- {hdx_python_api-6.6.3 → hdx_python_api-6.6.5}/tests/fixtures/config/hdx_resource_static.yaml +0 -0
- {hdx_python_api-6.6.3 → hdx_python_api-6.6.5}/tests/fixtures/config/hdx_resource_view_static.json +0 -0
- {hdx_python_api-6.6.3 → hdx_python_api-6.6.5}/tests/fixtures/config/hdx_resource_view_static.yaml +0 -0
- {hdx_python_api-6.6.3 → hdx_python_api-6.6.5}/tests/fixtures/config/hdx_showcase_static.json +0 -0
- {hdx_python_api-6.6.3 → hdx_python_api-6.6.5}/tests/fixtures/config/hdx_showcase_static.yaml +0 -0
- {hdx_python_api-6.6.3 → hdx_python_api-6.6.5}/tests/fixtures/config/hdx_user_static.json +0 -0
- {hdx_python_api-6.6.3 → hdx_python_api-6.6.5}/tests/fixtures/config/hdx_user_static.yaml +0 -0
- {hdx_python_api-6.6.3 → hdx_python_api-6.6.5}/tests/fixtures/config/hdx_vocabulary_static.json +0 -0
- {hdx_python_api-6.6.3 → hdx_python_api-6.6.5}/tests/fixtures/config/hdx_vocabulary_static.yaml +0 -0
- {hdx_python_api-6.6.3 → hdx_python_api-6.6.5}/tests/fixtures/config/project_configuration.json +0 -0
- {hdx_python_api-6.6.3 → hdx_python_api-6.6.5}/tests/fixtures/config/project_configuration.yaml +0 -0
- {hdx_python_api-6.6.3 → hdx_python_api-6.6.5}/tests/fixtures/config/user_agent_config.yaml +0 -0
- {hdx_python_api-6.6.3 → hdx_python_api-6.6.5}/tests/fixtures/config/user_agent_config2.yaml +0 -0
- {hdx_python_api-6.6.3 → hdx_python_api-6.6.5}/tests/fixtures/config/user_agent_config3.yaml +0 -0
- {hdx_python_api-6.6.3 → hdx_python_api-6.6.5}/tests/fixtures/config/user_agent_config_wrong.yaml +0 -0
- {hdx_python_api-6.6.3 → hdx_python_api-6.6.5}/tests/fixtures/dataset_search_results.yaml +0 -0
- {hdx_python_api-6.6.3 → hdx_python_api-6.6.5}/tests/fixtures/download_gen_resource/conflict_data_alg.csv +0 -0
- {hdx_python_api-6.6.3 → hdx_python_api-6.6.5}/tests/fixtures/download_gen_resource/min_qc_conflict_data_alg.csv +0 -0
- {hdx_python_api-6.6.3 → hdx_python_api-6.6.5}/tests/fixtures/download_gen_resource/qc_conflict_data_alg.csv +0 -0
- {hdx_python_api-6.6.3 → hdx_python_api-6.6.5}/tests/fixtures/download_gen_resource/test_data_no_data.csv +0 -0
- {hdx_python_api-6.6.3 → hdx_python_api-6.6.5}/tests/fixtures/download_gen_resource/test_data_no_years.csv +0 -0
- {hdx_python_api-6.6.3 → hdx_python_api-6.6.5}/tests/fixtures/empty.csv +0 -0
- {hdx_python_api-6.6.3 → hdx_python_api-6.6.5}/tests/fixtures/gen_resource/conflict_data_alg.csv +0 -0
- {hdx_python_api-6.6.3 → hdx_python_api-6.6.5}/tests/fixtures/gen_resource/min_qc_conflict_data_alg.csv +0 -0
- {hdx_python_api-6.6.3 → hdx_python_api-6.6.5}/tests/fixtures/gen_resource/qc_conflict_data_alg.csv +0 -0
- {hdx_python_api-6.6.3 → hdx_python_api-6.6.5}/tests/fixtures/gen_resource/test_data_no_data.csv +0 -0
- {hdx_python_api-6.6.3 → hdx_python_api-6.6.5}/tests/fixtures/gen_resource/test_data_no_years.csv +0 -0
- {hdx_python_api-6.6.3 → hdx_python_api-6.6.5}/tests/fixtures/organization_show_results.yaml +0 -0
- {hdx_python_api-6.6.3 → hdx_python_api-6.6.5}/tests/fixtures/qc_from_rows/qc_conflict_data_alg.csv +0 -0
- {hdx_python_api-6.6.3 → hdx_python_api-6.6.5}/tests/fixtures/qc_from_rows/qc_conflict_data_alg_one_col.csv +0 -0
- {hdx_python_api-6.6.3 → hdx_python_api-6.6.5}/tests/fixtures/resource_formats.json +0 -0
- {hdx_python_api-6.6.3 → hdx_python_api-6.6.5}/tests/fixtures/showcase_all_search_results.yaml +0 -0
- {hdx_python_api-6.6.3 → hdx_python_api-6.6.5}/tests/fixtures/size_hash/ACLED-All-Africa-File_20170101-to-20170708.xlsx +0 -0
- {hdx_python_api-6.6.3 → hdx_python_api-6.6.5}/tests/fixtures/state/analysis_dates.txt +0 -0
- {hdx_python_api-6.6.3 → hdx_python_api-6.6.5}/tests/fixtures/state/last_build_date.txt +0 -0
- {hdx_python_api-6.6.3 → hdx_python_api-6.6.5}/tests/fixtures/test_data.csv +0 -0
- {hdx_python_api-6.6.3 → hdx_python_api-6.6.5}/tests/fixtures/test_data.zip +0 -0
- {hdx_python_api-6.6.3 → hdx_python_api-6.6.5}/tests/fixtures/update_dataset_resources/dem_data_zwe.csv +0 -0
- {hdx_python_api-6.6.3 → hdx_python_api-6.6.5}/tests/fixtures/update_dataset_resources/dem_indicatorlist_zwe.csv +0 -0
- {hdx_python_api-6.6.3 → hdx_python_api-6.6.5}/tests/fixtures/update_dataset_resources/expected_resources_to_update.json +0 -0
- {hdx_python_api-6.6.3 → hdx_python_api-6.6.5}/tests/fixtures/update_dataset_resources/opri_data_zwe.csv +0 -0
- {hdx_python_api-6.6.3 → hdx_python_api-6.6.5}/tests/fixtures/update_dataset_resources/opri_indicatorlist_zwe.csv +0 -0
- {hdx_python_api-6.6.3 → hdx_python_api-6.6.5}/tests/fixtures/update_dataset_resources/opri_metadata_zwe.csv +0 -0
- {hdx_python_api-6.6.3 → hdx_python_api-6.6.5}/tests/fixtures/update_dataset_resources/qc_sdg_data_zwe.csv +0 -0
- {hdx_python_api-6.6.3 → hdx_python_api-6.6.5}/tests/fixtures/update_dataset_resources/sdg_data_zwe.csv +0 -0
- {hdx_python_api-6.6.3 → hdx_python_api-6.6.5}/tests/fixtures/update_dataset_resources/sdg_indicatorlist_zwe.csv +0 -0
- {hdx_python_api-6.6.3 → hdx_python_api-6.6.5}/tests/fixtures/update_dataset_resources/sdg_metadata_zwe.csv +0 -0
- {hdx_python_api-6.6.3 → hdx_python_api-6.6.5}/tests/fixtures/update_dataset_resources/unesco_dataset.json +0 -0
- {hdx_python_api-6.6.3 → hdx_python_api-6.6.5}/tests/fixtures/update_dataset_resources/unesco_update_dataset.json +0 -0
- {hdx_python_api-6.6.3 → hdx_python_api-6.6.5}/tests/fixtures/update_logic/update_logic_resources.yaml +0 -0
- {hdx_python_api-6.6.3 → hdx_python_api-6.6.5}/tests/fixtures/update_logic/update_logic_resources_new.yaml +0 -0
- {hdx_python_api-6.6.3 → hdx_python_api-6.6.5}/tests/hdx/__init__.py +0 -0
- {hdx_python_api-6.6.3 → hdx_python_api-6.6.5}/tests/hdx/api/__init__.py +0 -0
- {hdx_python_api-6.6.3 → hdx_python_api-6.6.5}/tests/hdx/api/test_ckan.py +0 -0
- {hdx_python_api-6.6.3 → hdx_python_api-6.6.5}/tests/hdx/api/test_configuration.py +0 -0
- {hdx_python_api-6.6.3 → hdx_python_api-6.6.5}/tests/hdx/api/test_locations.py +0 -0
- {hdx_python_api-6.6.3 → hdx_python_api-6.6.5}/tests/hdx/api/utilities/__init__.py +0 -0
- {hdx_python_api-6.6.3 → hdx_python_api-6.6.5}/tests/hdx/api/utilities/test_filestore_helper.py +0 -0
- {hdx_python_api-6.6.3 → hdx_python_api-6.6.5}/tests/hdx/api/utilities/test_hdx_error_handler.py +0 -0
- {hdx_python_api-6.6.3 → hdx_python_api-6.6.5}/tests/hdx/conftest.py +0 -0
- {hdx_python_api-6.6.3 → hdx_python_api-6.6.5}/tests/hdx/data/__init__.py +0 -0
- {hdx_python_api-6.6.3 → hdx_python_api-6.6.5}/tests/hdx/data/test_dataset_resource_generation.py +0 -0
- {hdx_python_api-6.6.3 → hdx_python_api-6.6.5}/tests/hdx/data/test_update_dataset_resources.py +0 -0
- {hdx_python_api-6.6.3 → hdx_python_api-6.6.5}/tests/hdx/data/test_update_logic.py +0 -0
- {hdx_python_api-6.6.3 → hdx_python_api-6.6.5}/tests/hdx/facades/__init__.py +0 -0
- {hdx_python_api-6.6.3 → hdx_python_api-6.6.5}/workingexample/my_code.py +0 -0
- {hdx_python_api-6.6.3 → hdx_python_api-6.6.5}/workingexample/my_resource.csv +0 -0
- {hdx_python_api-6.6.3 → hdx_python_api-6.6.5}/workingexample/my_resource.xlsx +0 -0
|
@@ -13,25 +13,22 @@ jobs:
|
|
|
13
13
|
url: https://pypi.org/p/hdx-python-api
|
|
14
14
|
|
|
15
15
|
permissions:
|
|
16
|
-
id-token: write
|
|
16
|
+
id-token: write
|
|
17
|
+
contents: read
|
|
17
18
|
|
|
18
19
|
steps:
|
|
19
20
|
- uses: actions/checkout@v6
|
|
21
|
+
|
|
20
22
|
- name: Get history and tags for versioning to work
|
|
21
23
|
run: |
|
|
22
24
|
git fetch --prune --unshallow
|
|
23
25
|
git fetch --depth=1 origin +refs/tags/*:refs/tags/*
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
- name:
|
|
29
|
-
run:
|
|
30
|
-
|
|
31
|
-
- name: Install Hatch
|
|
32
|
-
uses: pypa/hatch@install
|
|
33
|
-
- name: Build with hatch
|
|
34
|
-
run: |
|
|
35
|
-
hatch build
|
|
26
|
+
|
|
27
|
+
- name: Install uv
|
|
28
|
+
uses: astral-sh/setup-uv@v7
|
|
29
|
+
|
|
30
|
+
- name: Build with uv
|
|
31
|
+
run: uv build
|
|
32
|
+
|
|
36
33
|
- name: Publish distribution 📦 to PyPI
|
|
37
|
-
|
|
34
|
+
run: uv publish
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
name: Run tests
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
workflow_dispatch:
|
|
5
|
+
push:
|
|
6
|
+
branches-ignore: [gh-pages, "dependabot/**"]
|
|
7
|
+
pull_request:
|
|
8
|
+
branches-ignore: [gh-pages]
|
|
9
|
+
|
|
10
|
+
jobs:
|
|
11
|
+
build:
|
|
12
|
+
runs-on: ubuntu-latest
|
|
13
|
+
permissions:
|
|
14
|
+
contents: read
|
|
15
|
+
checks: write
|
|
16
|
+
pull-requests: write
|
|
17
|
+
|
|
18
|
+
steps:
|
|
19
|
+
- uses: actions/checkout@v6
|
|
20
|
+
|
|
21
|
+
- name: Install uv
|
|
22
|
+
uses: astral-sh/setup-uv@v7
|
|
23
|
+
with:
|
|
24
|
+
enable-cache: true
|
|
25
|
+
python-version: "3.13"
|
|
26
|
+
|
|
27
|
+
- name: Install dependencies
|
|
28
|
+
run: uv sync --frozen
|
|
29
|
+
|
|
30
|
+
- name: Check styling
|
|
31
|
+
run: |
|
|
32
|
+
uv run ruff format --check
|
|
33
|
+
uv run ruff check
|
|
34
|
+
|
|
35
|
+
- name: Test with pytest
|
|
36
|
+
env:
|
|
37
|
+
HDX_KEY_TEST: ${{ secrets.HDX_BOT_SCRAPERS_API_TOKEN }}
|
|
38
|
+
GSHEET_AUTH: ${{ secrets.HDX_PIPELINE_GSHEET_AUTH }}
|
|
39
|
+
run: uv run pytest
|
|
40
|
+
|
|
41
|
+
- name: Publish Unit Test Results
|
|
42
|
+
uses: EnricoMi/publish-unit-test-result-action@v2
|
|
43
|
+
if: always()
|
|
44
|
+
with:
|
|
45
|
+
files: test-results.xml
|
|
46
|
+
|
|
47
|
+
- name: Publish in Coveralls
|
|
48
|
+
uses: coverallsapp/github-action@v2
|
|
49
|
+
if: always()
|
|
50
|
+
with:
|
|
51
|
+
flag-name: tests
|
|
52
|
+
format: lcov
|
|
@@ -1,26 +1,27 @@
|
|
|
1
1
|
default_language_version:
|
|
2
|
-
|
|
2
|
+
python: python3.13
|
|
3
|
+
|
|
3
4
|
repos:
|
|
4
5
|
- repo: https://github.com/pre-commit/pre-commit-hooks
|
|
5
6
|
rev: v6.0.0
|
|
6
7
|
hooks:
|
|
7
8
|
- id: trailing-whitespace
|
|
9
|
+
exclude: (test_loader.py|pretty-false_sortkeys-false.yaml|pretty-false_sortkeys-true.yaml)
|
|
8
10
|
- id: end-of-file-fixer
|
|
11
|
+
exclude: (test_csv_processing_blanks.csv|test.txt)
|
|
9
12
|
- id: check-ast
|
|
13
|
+
|
|
10
14
|
- repo: https://github.com/astral-sh/ruff-pre-commit
|
|
11
|
-
rev: v0.14.
|
|
15
|
+
rev: v0.14.14
|
|
12
16
|
hooks:
|
|
13
17
|
# Run the linter.
|
|
14
18
|
- id: ruff-check
|
|
15
19
|
args: [ --fix ]
|
|
16
20
|
# Run the formatter.
|
|
17
21
|
- id: ruff-format
|
|
22
|
+
|
|
18
23
|
- repo: https://github.com/astral-sh/uv-pre-commit
|
|
19
|
-
rev: 0.9.
|
|
24
|
+
rev: 0.9.25
|
|
20
25
|
hooks:
|
|
21
|
-
#
|
|
22
|
-
- id:
|
|
23
|
-
name: pip-compile requirements.txt
|
|
24
|
-
files: pyproject.toml
|
|
25
|
-
args: [ pyproject.toml, --resolver=backtracking, --upgrade, -q,
|
|
26
|
-
-o, requirements.txt ]
|
|
26
|
+
# Ensure the lockfile is up-to-date with pyproject.toml
|
|
27
|
+
- id: uv-lock
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: hdx-python-api
|
|
3
|
-
Version: 6.6.
|
|
3
|
+
Version: 6.6.5
|
|
4
4
|
Summary: HDX Python API for interacting with the Humanitarian Data Exchange
|
|
5
5
|
Project-URL: Homepage, https://github.com/OCHA-DAP/hdx-python-api
|
|
6
6
|
Author: Michael Rans
|
|
@@ -18,31 +18,22 @@ Classifier: Operating System :: Unix
|
|
|
18
18
|
Classifier: Programming Language :: Python
|
|
19
19
|
Classifier: Programming Language :: Python :: 3
|
|
20
20
|
Classifier: Programming Language :: Python :: 3 :: Only
|
|
21
|
-
Classifier: Programming Language :: Python :: 3.8
|
|
22
|
-
Classifier: Programming Language :: Python :: 3.9
|
|
23
21
|
Classifier: Programming Language :: Python :: 3.10
|
|
24
22
|
Classifier: Programming Language :: Python :: 3.11
|
|
25
23
|
Classifier: Programming Language :: Python :: 3.12
|
|
24
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
25
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
26
26
|
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
27
27
|
Requires-Python: >=3.10
|
|
28
28
|
Requires-Dist: ckanapi>=4.8
|
|
29
29
|
Requires-Dist: defopt>=7.0.0
|
|
30
30
|
Requires-Dist: email-validator
|
|
31
31
|
Requires-Dist: hdx-python-country>=4.0.1
|
|
32
|
-
Requires-Dist: hdx-python-utilities>=4.0.
|
|
33
|
-
Requires-Dist: libhxl>=5.2.2
|
|
32
|
+
Requires-Dist: hdx-python-utilities>=4.0.4
|
|
34
33
|
Requires-Dist: makefun
|
|
35
|
-
Requires-Dist: quantulum3
|
|
36
34
|
Requires-Dist: requests
|
|
37
|
-
Provides-Extra: dev
|
|
38
|
-
Requires-Dist: pre-commit; extra == 'dev'
|
|
39
35
|
Provides-Extra: docs
|
|
40
36
|
Requires-Dist: mkapi; extra == 'docs'
|
|
41
|
-
Provides-Extra: test
|
|
42
|
-
Requires-Dist: gspread; extra == 'test'
|
|
43
|
-
Requires-Dist: pytest; extra == 'test'
|
|
44
|
-
Requires-Dist: pytest-check; extra == 'test'
|
|
45
|
-
Requires-Dist: pytest-cov; extra == 'test'
|
|
46
37
|
Description-Content-Type: text/markdown
|
|
47
38
|
|
|
48
39
|
[](https://github.com/OCHA-DAP/hdx-python-api/actions/workflows/run-python-tests.yaml)
|
|
@@ -61,3 +52,87 @@ For more information, please read the
|
|
|
61
52
|
This library is part of the [Humanitarian Data Exchange](https://data.humdata.org/)
|
|
62
53
|
(HDX) project. If you have humanitarian related data, please upload your datasets to
|
|
63
54
|
HDX.
|
|
55
|
+
|
|
56
|
+
# Development
|
|
57
|
+
|
|
58
|
+
## Environment
|
|
59
|
+
|
|
60
|
+
Development is currently done using Python 3.13. The environment can be created with:
|
|
61
|
+
|
|
62
|
+
```shell
|
|
63
|
+
uv sync
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
This creates a .venv folder with the versions specified in the project's uv.lock file.
|
|
67
|
+
|
|
68
|
+
### Pre-commit
|
|
69
|
+
|
|
70
|
+
pre-commit will be installed when syncing uv. It is run every time you make a git
|
|
71
|
+
commit if you call it like this:
|
|
72
|
+
|
|
73
|
+
```shell
|
|
74
|
+
pre-commit install
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
With pre-commit, all code is formatted according to
|
|
78
|
+
[ruff](https://docs.astral.sh/ruff/) guidelines.
|
|
79
|
+
|
|
80
|
+
To check if your changes pass pre-commit without committing, run:
|
|
81
|
+
|
|
82
|
+
```shell
|
|
83
|
+
pre-commit run --all-files
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
## Packages
|
|
87
|
+
|
|
88
|
+
[uv](https://github.com/astral-sh/uv) is used for package management. If
|
|
89
|
+
you’ve introduced a new package to the source code (i.e. anywhere in `src/`),
|
|
90
|
+
please add it to the `project.dependencies` section of `pyproject.toml` with
|
|
91
|
+
any known version constraints.
|
|
92
|
+
|
|
93
|
+
To add packages required only for testing, add them to the
|
|
94
|
+
`[dependency-groups]`.
|
|
95
|
+
|
|
96
|
+
Any changes to the dependencies will be automatically reflected in
|
|
97
|
+
`uv.lock` with `pre-commit`, but you can re-generate the files without committing by
|
|
98
|
+
executing:
|
|
99
|
+
|
|
100
|
+
```shell
|
|
101
|
+
uv lock --upgrade
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
## Project
|
|
105
|
+
|
|
106
|
+
[uv](https://github.com/astral-sh/uv) is used for project management. The project can be
|
|
107
|
+
built using:
|
|
108
|
+
|
|
109
|
+
```shell
|
|
110
|
+
uv build
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
Linting and syntax checking can be run with:
|
|
114
|
+
|
|
115
|
+
```shell
|
|
116
|
+
uv run ruff check
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
To run the tests and view coverage, execute:
|
|
120
|
+
|
|
121
|
+
```shell
|
|
122
|
+
uv run pytest
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
For the `test_ckan.py` test to run successfully, some configuration is required:
|
|
126
|
+
|
|
127
|
+
1. The environment variable HDX_KEY_TEST needs to contain a valid key from the HDX demo
|
|
128
|
+
server at https://demo.data-humdata-org.ahconu.org/
|
|
129
|
+
1. Authentication details for Google Sheets need to be obtained and either saved in a
|
|
130
|
+
file named `.gsheet_auth.json` in the home directory (~) or placed in an environment
|
|
131
|
+
variable `GSHEET_AUTH`. The file is preferred for Windows systems since adding such a
|
|
132
|
+
long text string to an environment variable in Windows is challenging.
|
|
133
|
+
|
|
134
|
+
## Documentation
|
|
135
|
+
|
|
136
|
+
The documentation, including API documentation, is generated using ReadtheDocs and
|
|
137
|
+
MkDocs with Material. As you change the source code, remember to update the
|
|
138
|
+
documentation at `documentation/index.md`.
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
[](https://github.com/OCHA-DAP/hdx-python-api/actions/workflows/run-python-tests.yaml)
|
|
2
|
+
[](https://coveralls.io/github/OCHA-DAP/hdx-python-api?branch=main)
|
|
3
|
+
[](https://github.com/astral-sh/ruff)
|
|
4
|
+
[](https://pypistats.org/packages/hdx-python-api)
|
|
5
|
+
|
|
6
|
+
The HDX Python API Library is designed to enable you to easily develop code that
|
|
7
|
+
interacts with the [Humanitarian Data Exchange](https://data.humdata.org/) (HDX)
|
|
8
|
+
platform. The major goal of the library is to make pushing and pulling data from HDX as
|
|
9
|
+
simple as possible for the end user.
|
|
10
|
+
|
|
11
|
+
For more information, please read the
|
|
12
|
+
[documentation](https://hdx-python-api.readthedocs.io/en/latest/).
|
|
13
|
+
|
|
14
|
+
This library is part of the [Humanitarian Data Exchange](https://data.humdata.org/)
|
|
15
|
+
(HDX) project. If you have humanitarian related data, please upload your datasets to
|
|
16
|
+
HDX.
|
|
17
|
+
|
|
18
|
+
# Development
|
|
19
|
+
|
|
20
|
+
## Environment
|
|
21
|
+
|
|
22
|
+
Development is currently done using Python 3.13. The environment can be created with:
|
|
23
|
+
|
|
24
|
+
```shell
|
|
25
|
+
uv sync
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
This creates a .venv folder with the versions specified in the project's uv.lock file.
|
|
29
|
+
|
|
30
|
+
### Pre-commit
|
|
31
|
+
|
|
32
|
+
pre-commit will be installed when syncing uv. It is run every time you make a git
|
|
33
|
+
commit if you call it like this:
|
|
34
|
+
|
|
35
|
+
```shell
|
|
36
|
+
pre-commit install
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
With pre-commit, all code is formatted according to
|
|
40
|
+
[ruff](https://docs.astral.sh/ruff/) guidelines.
|
|
41
|
+
|
|
42
|
+
To check if your changes pass pre-commit without committing, run:
|
|
43
|
+
|
|
44
|
+
```shell
|
|
45
|
+
pre-commit run --all-files
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
## Packages
|
|
49
|
+
|
|
50
|
+
[uv](https://github.com/astral-sh/uv) is used for package management. If
|
|
51
|
+
you’ve introduced a new package to the source code (i.e. anywhere in `src/`),
|
|
52
|
+
please add it to the `project.dependencies` section of `pyproject.toml` with
|
|
53
|
+
any known version constraints.
|
|
54
|
+
|
|
55
|
+
To add packages required only for testing, add them to the
|
|
56
|
+
`[dependency-groups]`.
|
|
57
|
+
|
|
58
|
+
Any changes to the dependencies will be automatically reflected in
|
|
59
|
+
`uv.lock` with `pre-commit`, but you can re-generate the files without committing by
|
|
60
|
+
executing:
|
|
61
|
+
|
|
62
|
+
```shell
|
|
63
|
+
uv lock --upgrade
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
## Project
|
|
67
|
+
|
|
68
|
+
[uv](https://github.com/astral-sh/uv) is used for project management. The project can be
|
|
69
|
+
built using:
|
|
70
|
+
|
|
71
|
+
```shell
|
|
72
|
+
uv build
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
Linting and syntax checking can be run with:
|
|
76
|
+
|
|
77
|
+
```shell
|
|
78
|
+
uv run ruff check
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
To run the tests and view coverage, execute:
|
|
82
|
+
|
|
83
|
+
```shell
|
|
84
|
+
uv run pytest
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
For the `test_ckan.py` test to run successfully, some configuration is required:
|
|
88
|
+
|
|
89
|
+
1. The environment variable HDX_KEY_TEST needs to contain a valid key from the HDX demo
|
|
90
|
+
server at https://demo.data-humdata-org.ahconu.org/
|
|
91
|
+
1. Authentication details for Google Sheets need to be obtained and either saved in a
|
|
92
|
+
file named `.gsheet_auth.json` in the home directory (~) or placed in an environment
|
|
93
|
+
variable `GSHEET_AUTH`. The file is preferred for Windows systems since adding such a
|
|
94
|
+
long text string to an environment variable in Windows is challenging.
|
|
95
|
+
|
|
96
|
+
## Documentation
|
|
97
|
+
|
|
98
|
+
The documentation, including API documentation, is generated using ReadtheDocs and
|
|
99
|
+
MkDocs with Material. As you change the source code, remember to update the
|
|
100
|
+
documentation at `documentation/index.md`.
|
|
@@ -54,6 +54,8 @@ The library has detailed API documentation which can be found in the menu at the
|
|
|
54
54
|
|
|
55
55
|
|
|
56
56
|
## Breaking Changes
|
|
57
|
+
From 6.6.5, removed DatasetTitleHelper class and Dataset method remove_dates_from_title
|
|
58
|
+
|
|
57
59
|
From 6.6.0, Python 3.10 or later is required
|
|
58
60
|
|
|
59
61
|
From 6.5.7, get_size_and_hash moved to HDX Python Utilities
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
#########################
|
|
2
|
+
# Project Configuration #
|
|
3
|
+
#########################
|
|
4
|
+
|
|
5
|
+
[build-system]
|
|
6
|
+
requires = ["hatchling", "hatch-vcs"]
|
|
7
|
+
build-backend = "hatchling.build"
|
|
8
|
+
|
|
9
|
+
[project]
|
|
10
|
+
name = "hdx-python-api"
|
|
11
|
+
description = "HDX Python API for interacting with the Humanitarian Data Exchange"
|
|
12
|
+
authors = [{name = "Michael Rans"}]
|
|
13
|
+
license = {text = "MIT"}
|
|
14
|
+
keywords = ["HDX", "API", "CKAN", "humanitarian data exchange"]
|
|
15
|
+
classifiers = [
|
|
16
|
+
"Development Status :: 5 - Production/Stable",
|
|
17
|
+
"Topic :: Software Development :: Libraries :: Python Modules",
|
|
18
|
+
"Programming Language :: Python",
|
|
19
|
+
"Programming Language :: Python :: 3",
|
|
20
|
+
"Programming Language :: Python :: 3 :: Only",
|
|
21
|
+
"Programming Language :: Python :: 3.10",
|
|
22
|
+
"Programming Language :: Python :: 3.11",
|
|
23
|
+
"Programming Language :: Python :: 3.12",
|
|
24
|
+
"Programming Language :: Python :: 3.13",
|
|
25
|
+
"Programming Language :: Python :: 3.14",
|
|
26
|
+
"Intended Audience :: Developers",
|
|
27
|
+
"License :: OSI Approved :: MIT License",
|
|
28
|
+
"Natural Language :: English",
|
|
29
|
+
"Operating System :: POSIX :: Linux",
|
|
30
|
+
"Operating System :: Unix",
|
|
31
|
+
"Operating System :: MacOS",
|
|
32
|
+
"Operating System :: Microsoft :: Windows",
|
|
33
|
+
]
|
|
34
|
+
readme = "README.md"
|
|
35
|
+
dynamic = ["version"]
|
|
36
|
+
requires-python = ">=3.10"
|
|
37
|
+
|
|
38
|
+
dependencies = [
|
|
39
|
+
"ckanapi>=4.8",
|
|
40
|
+
"defopt>=7.0.0",
|
|
41
|
+
"email_validator",
|
|
42
|
+
"hdx-python-country>=4.0.1",
|
|
43
|
+
"hdx-python-utilities>=4.0.4",
|
|
44
|
+
"makefun",
|
|
45
|
+
"requests",
|
|
46
|
+
]
|
|
47
|
+
|
|
48
|
+
[project.optional-dependencies]
|
|
49
|
+
docs = ["mkapi"]
|
|
50
|
+
|
|
51
|
+
[dependency-groups]
|
|
52
|
+
dev = [
|
|
53
|
+
"gspread",
|
|
54
|
+
"pytest",
|
|
55
|
+
"pytest-check",
|
|
56
|
+
"pytest-cov",
|
|
57
|
+
"pytest-mock",
|
|
58
|
+
"pre-commit",
|
|
59
|
+
"ruff==0.14.14",
|
|
60
|
+
]
|
|
61
|
+
|
|
62
|
+
[project.urls]
|
|
63
|
+
Homepage = "https://github.com/OCHA-DAP/hdx-python-api"
|
|
64
|
+
|
|
65
|
+
# ----------------------------------------------------------------------------
|
|
66
|
+
# Hatchling (Build & Versioning)
|
|
67
|
+
# ----------------------------------------------------------------------------
|
|
68
|
+
|
|
69
|
+
[tool.hatch.version]
|
|
70
|
+
source = "vcs"
|
|
71
|
+
|
|
72
|
+
[tool.hatch.version.raw-options]
|
|
73
|
+
local_scheme = "no-local-version"
|
|
74
|
+
version_scheme = "python-simplified-semver"
|
|
75
|
+
|
|
76
|
+
[tool.hatch.build.hooks.vcs]
|
|
77
|
+
version-file = "src/hdx/api/_version.py"
|
|
78
|
+
|
|
79
|
+
[tool.hatch.build.targets.wheel]
|
|
80
|
+
packages = ["src/hdx"]
|
|
81
|
+
|
|
82
|
+
[tool.hatch.metadata]
|
|
83
|
+
allow-direct-references = true
|
|
84
|
+
|
|
85
|
+
# ----------------------------------------------------------------------------
|
|
86
|
+
# Ruff (Linting & Formatting)
|
|
87
|
+
# ----------------------------------------------------------------------------
|
|
88
|
+
|
|
89
|
+
[tool.ruff]
|
|
90
|
+
target-version = "py310"
|
|
91
|
+
src = ["src"]
|
|
92
|
+
exclude = ["_version.py"]
|
|
93
|
+
|
|
94
|
+
[tool.ruff.lint]
|
|
95
|
+
# Defaults are E (pycodestyle) and F (pyflakes). We extend them:
|
|
96
|
+
extend-select = [
|
|
97
|
+
"I", # isort
|
|
98
|
+
"UP", # pyupgrade
|
|
99
|
+
]
|
|
100
|
+
ignore = [
|
|
101
|
+
"E501", # Line too long
|
|
102
|
+
]
|
|
103
|
+
|
|
104
|
+
[tool.ruff.lint.isort]
|
|
105
|
+
known-local-folder = ["hdx.api", "hdx.data", "hdx.facades"]
|
|
106
|
+
known-third-party = [
|
|
107
|
+
"hdx.location",
|
|
108
|
+
"hdx.utilities",
|
|
109
|
+
]
|
|
110
|
+
|
|
111
|
+
# ----------------------------------------------------------------------------
|
|
112
|
+
# Pytest (Testing)
|
|
113
|
+
# ----------------------------------------------------------------------------
|
|
114
|
+
|
|
115
|
+
[tool.pytest.ini_options]
|
|
116
|
+
pythonpath = "src"
|
|
117
|
+
log_cli = true
|
|
118
|
+
addopts = """
|
|
119
|
+
--color=yes
|
|
120
|
+
--rootdir=.
|
|
121
|
+
--junitxml=test-results.xml
|
|
122
|
+
--cov
|
|
123
|
+
--no-cov-on-fail
|
|
124
|
+
--cov-report=lcov
|
|
125
|
+
--cov-report=term-missing
|
|
126
|
+
"""
|
|
127
|
+
|
|
128
|
+
# ----------------------------------------------------------------------------
|
|
129
|
+
# Coverage (Reporting)
|
|
130
|
+
# ----------------------------------------------------------------------------
|
|
131
|
+
|
|
132
|
+
[tool.coverage.run]
|
|
133
|
+
source = ["src"]
|
|
134
|
+
omit = ["*/_version.py"]
|
|
135
|
+
|
|
136
|
+
[tool.coverage.report]
|
|
137
|
+
exclude_also = [
|
|
138
|
+
"from ._version",
|
|
139
|
+
"def __repr__",
|
|
140
|
+
"if self.debug:",
|
|
141
|
+
"if settings.DEBUG",
|
|
142
|
+
"raise AssertionError",
|
|
143
|
+
"raise NotImplementedError",
|
|
144
|
+
"if 0:",
|
|
145
|
+
"if __name__ == .__main__.:",
|
|
146
|
+
"if TYPE_CHECKING:",
|
|
147
|
+
"@(abc\\.)?abstractmethod",
|
|
148
|
+
]
|
|
@@ -28,7 +28,7 @@ version_tuple: VERSION_TUPLE
|
|
|
28
28
|
commit_id: COMMIT_ID
|
|
29
29
|
__commit_id__: COMMIT_ID
|
|
30
30
|
|
|
31
|
-
__version__ = version = '6.6.
|
|
32
|
-
__version_tuple__ = version_tuple = (6, 6,
|
|
31
|
+
__version__ = version = '6.6.5'
|
|
32
|
+
__version_tuple__ = version_tuple = (6, 6, 5)
|
|
33
33
|
|
|
34
34
|
__commit_id__ = commit_id = None
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import re
|
|
2
|
+
|
|
3
|
+
from hdx.utilities.session import get_session
|
|
4
|
+
from requests import RequestException, Session
|
|
5
|
+
|
|
6
|
+
import hdx.data.dataset
|
|
7
|
+
import hdx.data.resource
|
|
8
|
+
from hdx.api.configuration import Configuration
|
|
9
|
+
|
|
10
|
+
GOOGLE_DRIVE_URL = re.compile(r"^https?://drive.google.com/open\?id=([0-9A-Za-z_-]+)$")
|
|
11
|
+
GOOGLE_SHEETS_URL = re.compile(
|
|
12
|
+
r"^https?://[^/]+google.com/.*[^0-9A-Za-z_-]([0-9A-Za-z_-]{44})(?:.*gid=([0-9]+))?.*$"
|
|
13
|
+
)
|
|
14
|
+
GOOGLE_SHEETS_XLSX_URL = re.compile(
|
|
15
|
+
r"^https?://[^/]+google.com/.*[^0-9A-Za-z_-]([0-9A-Za-z_-]{33})(?:.*gid=([0-9]+))?.*$"
|
|
16
|
+
)
|
|
17
|
+
GOOGLE_FILE_URL = re.compile(r"https?://drive.google.com/file/d/([0-9A-Za-z_-]+)/.*$")
|
|
18
|
+
DROPBOX_URL = re.compile(r"^https://www.dropbox.com/s/([0-9a-z]{15})/([^?]+)\?dl=[01]$")
|
|
19
|
+
CKAN_URL = re.compile(
|
|
20
|
+
r"^(https?://[^/]+)/dataset/([^/]+)(?:/resource/([a-z0-9-]{36}))?$"
|
|
21
|
+
)
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def get_ckan_ready_session(configuration: Configuration) -> Session:
|
|
25
|
+
"""Get Session object setup to access CKAN
|
|
26
|
+
|
|
27
|
+
Args:
|
|
28
|
+
configuration: Configuration object
|
|
29
|
+
|
|
30
|
+
Returns:
|
|
31
|
+
Session object setup to access CKAN
|
|
32
|
+
"""
|
|
33
|
+
apikey = configuration.get_api_key()
|
|
34
|
+
if apikey:
|
|
35
|
+
headers = {"Authorization": apikey}
|
|
36
|
+
else:
|
|
37
|
+
headers = None
|
|
38
|
+
session = get_session(
|
|
39
|
+
full_agent=configuration.get_user_agent(), use_env=False, headers=headers
|
|
40
|
+
)
|
|
41
|
+
return session
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def follow_url(
|
|
45
|
+
url: str, configuration: Configuration | None = None, session: Session | None = None
|
|
46
|
+
) -> str:
|
|
47
|
+
"""Follow a URL to get the direct-download URL after any redirects. Either a
|
|
48
|
+
Configuration object or Session object must be provided
|
|
49
|
+
|
|
50
|
+
Args:
|
|
51
|
+
url: URL to follow
|
|
52
|
+
configuration: Configuration object. Defaults to None.
|
|
53
|
+
session: Session object to use. Defaults to None.
|
|
54
|
+
|
|
55
|
+
Returns:
|
|
56
|
+
The direct-download URL
|
|
57
|
+
|
|
58
|
+
"""
|
|
59
|
+
try:
|
|
60
|
+
if session is None:
|
|
61
|
+
if configuration is None:
|
|
62
|
+
raise ValueError(
|
|
63
|
+
"Either Session or Configuration object must be provided!"
|
|
64
|
+
)
|
|
65
|
+
session = get_ckan_ready_session(configuration)
|
|
66
|
+
|
|
67
|
+
# Is it a CKAN resource? (Assumes the v.3 API for now)
|
|
68
|
+
result = CKAN_URL.match(url)
|
|
69
|
+
if result:
|
|
70
|
+
result = _get_ckan_urls(result.group(2), result.group(3))
|
|
71
|
+
if result:
|
|
72
|
+
return result
|
|
73
|
+
|
|
74
|
+
# Is it a Google Drive "open" URL?
|
|
75
|
+
result = GOOGLE_DRIVE_URL.match(url)
|
|
76
|
+
if result:
|
|
77
|
+
response = session.head(url)
|
|
78
|
+
if response.is_redirect:
|
|
79
|
+
return response.headers["Location"]
|
|
80
|
+
|
|
81
|
+
#
|
|
82
|
+
# Stage 2: rewrite URLs to get direct-download links
|
|
83
|
+
#
|
|
84
|
+
|
|
85
|
+
# Is it a Google *Sheet*?
|
|
86
|
+
result = GOOGLE_SHEETS_URL.match(url)
|
|
87
|
+
if result and not re.search(r"/pub", url):
|
|
88
|
+
if result.group(2):
|
|
89
|
+
return f"https://docs.google.com/spreadsheets/d/{result.group(1)}/export?format=csv&gid={result.group(2)}"
|
|
90
|
+
return f"https://docs.google.com/spreadsheets/d/{result.group(1)}/export?format=csv"
|
|
91
|
+
|
|
92
|
+
# Is it a Google Drive *file*?
|
|
93
|
+
result = GOOGLE_FILE_URL.match(url)
|
|
94
|
+
if not result:
|
|
95
|
+
result = GOOGLE_SHEETS_XLSX_URL.match(url)
|
|
96
|
+
if result and not re.search(r"/pub", url):
|
|
97
|
+
return f"https://drive.google.com/uc?export=download&id={result.group(1)}"
|
|
98
|
+
|
|
99
|
+
# Is it a Dropbox URL?
|
|
100
|
+
result = DROPBOX_URL.match(url)
|
|
101
|
+
if result:
|
|
102
|
+
return f"https://www.dropbox.com/s/{result.group(1)}/{result.group(2)}?dl=1"
|
|
103
|
+
except RequestException:
|
|
104
|
+
pass
|
|
105
|
+
# No changes
|
|
106
|
+
return url
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
def _get_ckan_urls(dataset_id: str, resource_id: str) -> str | None:
|
|
110
|
+
"""Look up a CKAN download URL starting from a dataset or resource page
|
|
111
|
+
|
|
112
|
+
If the link is to a dataset page, try the first resource. If it's
|
|
113
|
+
to a resource page, look up the resource's download link. Either
|
|
114
|
+
dataset_id or resource_id is required (will prefer resource_id
|
|
115
|
+
over dataset_id).
|
|
116
|
+
|
|
117
|
+
Args:
|
|
118
|
+
dataset_id: the CKAN dataset ID, or None if unavailable
|
|
119
|
+
resource_id: the CKAN resource ID, or None if unavailable
|
|
120
|
+
|
|
121
|
+
Returns:
|
|
122
|
+
The direct-download URL for the CKAN dataset
|
|
123
|
+
"""
|
|
124
|
+
if resource_id:
|
|
125
|
+
resource = hdx.data.resource.Resource.read_from_hdx(resource_id)
|
|
126
|
+
if resource:
|
|
127
|
+
return resource["url"]
|
|
128
|
+
|
|
129
|
+
dataset = hdx.data.dataset.Dataset.read_from_hdx(dataset_id)
|
|
130
|
+
if not dataset:
|
|
131
|
+
return None
|
|
132
|
+
for resource in dataset.get_resources():
|
|
133
|
+
if url := resource.get("url"):
|
|
134
|
+
return url
|
|
135
|
+
return None
|