Spaces:
Running
Running
Download src/utils/helpers.py from reputeradar/ioc-core: direct link, hf CLI and curl.
- Browser
- Download file 840 Bytes
-
https://huggingface.co/spaces/reputeradar/ioc-core/resolve/main/src/utils/helpers.py
- Command line
-
hf download hf://spaces/reputeradar/ioc-core/src/utils/helpers.py
-
curl -L -o helpers.py https://huggingface.co/spaces/reputeradar/ioc-core/resolve/main/src/utils/helpers.py
840 Bytes
| """Helper utility functions.""" | |
| import pycountry | |
| def get_country_name(country_code: str) -> str: | |
| """ | |
| Convert ISO country code to full country name. | |
| Args: | |
| country_code: Two-letter ISO country code (e.g., 'US') | |
| Returns: | |
| Full country name or the original code if not found | |
| """ | |
| try: | |
| country = pycountry.countries.get(alpha_2=country_code) | |
| return country.name if country else country_code | |
| except (KeyError, AttributeError): | |
| return country_code | |
| def format_percentage(value: float, decimals: int = 2) -> float: | |
| """ | |
| Format a percentage value to specified decimal places. | |
| Args: | |
| value: The percentage value | |
| decimals: Number of decimal places (default: 2) | |
| Returns: | |
| Formatted percentage value | |
| """ | |
| return round(value, decimals) | |