Skip to content

Commit

Permalink
v1.6.1; bug fixes, new api endpoint, test case fixes, get_script changes
Browse files Browse the repository at this point in the history
  • Loading branch information
amckenna41 committed Jun 8, 2024
1 parent 08f27f6 commit e4d8f4b
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 13 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,18 @@

## v1.6.1 - June 2024


### Added
- list_subdivisions endpoint added to API that returns list of all subdivision codes per country
- Unit tests for flag_url function in update_subdivisions script
- Separate function for extracting and parsing data attributes from RestCountries API
- Added raise_for_status error catcher for requests library


### Changed
- Rotate user agent headers for any scripts using requests.get


### Fixed
- Error in request URL for RestCountries API in update_subdivisions script
- Raise TypeError if invalid data type input to export_iso3166_2 function rather than system crashing
Expand Down
7 changes: 5 additions & 2 deletions .github/workflows/build_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ jobs:
#unit tests using unittest framework
- name: Running unit tests
env:
GOOGLE_MAPS_API_KEY: ${{ secrets.GOOGLE_MAPS_API_KEY }}
run: |
echo "Testing using unittest..."
python3 -m unittest discover tests -v
Expand Down Expand Up @@ -154,8 +156,9 @@ jobs:
#generate codecov report using pytest
- name: Generate Coverage report
run: |
pytest --cov tests/
env:
GOOGLE_MAPS_API_KEY: ${{ secrets.GOOGLE_MAPS_API_KEY }}
run: pytest --cov tests/

#upload to Code Coverage, only if matrix python version is 3.10
- name: Upload Coverage Report to Codecov
Expand Down
1 change: 1 addition & 0 deletions API.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ The other endpoints available in the API are:
* https://iso3166-2-api.vercel.app/api/country_name/<input_country_name>
* https://iso3166-2-api.vercel.app/api/subdivision/<input_subdivision>
* https://iso3166-2-api.vercel.app/api/name/<input_subdivision_name>
* https://iso3166-2-api.vercel.app/api/list_subdivisions

Six paths/endpoints are available in the API - `/api/all`, `/api/alpha`, `/api/country_name`, `/api/subdivision`, `/api/name` and `/api/list_subdivisions`.

Expand Down
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Table of Contents
- [Installation](#installation)
- [Usage](#usage)
- [Documentation](#documentation)
- [Usage](#usage-iso3166_2_scriptsupdate_subdivisionspy)
- [Usage](#usage)
- [Directories](#directories)
- [Issues or Contributing](#issues-or-contributing)
- [Contact](#contact)
Expand Down Expand Up @@ -85,7 +85,7 @@ The other endpoints available in the API are:
* https://iso3166-2-api.vercel.app/api/subdivision/<input_subdivision>
* https://iso3166-2-api.vercel.app/api/name/<input_subdivision_name>

Five paths/endpoints are available in the API - `/api/all`, `/api/alpha`, `/api/country_name`, `/api/subdivision` and `/api/name`.
Six paths/endpoints are available in the API - `/api/all`, `/api/alpha`, `/api/country_name`, `/api/subdivision`, `/api/name` and `/api/list_subdivisions`.

* `/api/all`: get all of the ISO 3166 subdivision data for all countries.

Expand All @@ -97,6 +97,8 @@ Five paths/endpoints are available in the API - `/api/all`, `/api/alpha`, `/api/

* `/api/name/`: get all of the ISO 3166 subdivision data for 1 or more ISO 3166-2 subdivision names, e.g `/api/name/Derry`. You can also input a comma separated list of subdivision name from the same or different countries and the data for each will be returned e.g `/api/name/Paris,Frankfurt,Rimini`. A closeness function is utilised to find the matching subdivision name, if no exact name match found then the most approximate subdivisions will be returned. Some subdivisions may have the same name, in this case each subdivision and its data will be returned e.g `/api/name/Saint George` (this example returns 5 subdivisions). This endpoint also has the likeness score (`?likeness=`) query string parameter that can be appended to the URL. This can be set between 1 - 100, representing a % of likeness to the input name the return subdivisions should be, e.g: a likeness score of 90 will return fewer potential matches whose name only match to a high degree compared to a score of 10 which will create a larger search space, thus returning more potential subdivision matches. A default likeness of 100 (exact match) is used, if no matching subdivision is found then this is reduced to 90. If an invalid subdivision name that doesn't match any is input then an error will be raised.

* `/api/list_subdivisions`: get list of all the subdivision codes for all countries.

* `/api`: main homepage and API documentation.

The API documentation and usage with all useful commands and examples to the API is available on the [API.md][api_md] file. A demo of the software and API is available [here][demo].
Expand Down Expand Up @@ -228,7 +230,7 @@ Documentation for installation and usage of the software and API is available on

ISO 3166-2 Scripts
------------------
* The [`iso3166_2_scripts/get_iso3166_2.py`](https://github.com/amckenna41/iso3166-2/blob/main/iso3166_2_scripts) script is used for pulling and exporting the latest ISO 3166-2 data from the various data sources
* The [`iso3166_2_scripts/get_iso3166_2.py`](https://github.com/amckenna41/iso3166-2/blob/main/iso3166_2_scripts) script is used for pulling and exporting the latest ISO 3166-2 data from the various data sources. In this script you can also export additional attributes for each country/subdivision via the RestCountries API.
* The [`iso3166_2_scripts/update_subdivisions.py`](https://github.com/amckenna41/iso3166-2/blob/main/iso3166_2_scripts) script is used for adding, amending and or deleting subdivisions to the `iso3166-2` software and object.

Please visit the [README](https://github.com/amckenna41/iso3166-2/blob/main/iso3166_2_scripts) of the `iso3166_2_scripts` folder for more in depth info about the usage and requirements of the above two scripts <b>vital</b> to the `iso3166-2` software.
Expand Down
18 changes: 10 additions & 8 deletions docs/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ The other endpoints available in the API are:
* https://iso3166-2-api.vercel.app/api/name/<input_name>
* https://iso3166-2-api.vercel.app/api/list_subdivisions

Five paths/endpoints are available in the API - `/api/all`, `/api/alpha`, `/api/subdivision`, `/api/country_name`, `/api/name` and `/api/list_subdivisions`.
Six paths/endpoints are available in the API - `/api/all`, `/api/alpha`, `/api/subdivision`, `/api/country_name`, `/api/name` and `/api/list_subdivisions`.

* `/api/all`: get all of the ISO 3166 subdivision data for all countries.

Expand Down Expand Up @@ -221,12 +221,6 @@ curl::
$ curl -i https://iso3166-2-api.vercel.app/api/name/Northern?likeness=0.8
$ curl -i https://iso3166-2-api.vercel.app/api/name/Southern?likeness=0.8
.. note::
A demo of the software and API is available |demo_link|.
.. |demo_link| raw:: html
<a href="https://colab.research.google.com/drive/1btfEx23bgWdkUPiwdwlDqKkmUp1S-_7U?usp=sharing" target="_blank">here</a>
Get list of all subdivision codes per country
---------------------------------------------
Expand All @@ -247,4 +241,12 @@ Python Requests:
curl::
$ curl -i https://iso3166-2-api.vercel.app/api/list_subdivisions
$ curl -i https://iso3166-2-api.vercel.app/api/list_subdivisions
.. note::
A demo of the software and API is available |demo_link|.
.. |demo_link| raw:: html
<a href="https://colab.research.google.com/drive/1btfEx23bgWdkUPiwdwlDqKkmUp1S-_7U?usp=sharing" target="_blank">here</a>
2 changes: 2 additions & 0 deletions iso3166_2_scripts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ python3 iso3166_2_scripts/update_subdivisions.py --alpha_code=FR --subdivision_c
python3 iso3166_2_scripts/update_subdivisions.py --subdivision_csv=new_subdivisions.csv
```

[Back to top](#TOP)


[python]: https://www.python.org/downloads/release/python-360/
[requests]: https://requests.readthedocs.io/
Expand Down

0 comments on commit e4d8f4b

Please sign in to comment.