Spaces:
Sleeping
Sleeping
Download utils.py from yashgori20/ThinklySEO: direct link, hf CLI and curl.
- Browser
- Download file 571 Bytes
-
https://huggingface.co/spaces/yashgori20/ThinklySEO/resolve/main/utils.py
- Command line
-
hf download hf://spaces/yashgori20/ThinklySEO/utils.py
-
curl -L -o utils.py https://huggingface.co/spaces/yashgori20/ThinklySEO/resolve/main/utils.py
571 Bytes
| """ | |
| Utility helper functions for SEO Report Generator | |
| """ | |
| def safe_pct(n, d): | |
| """Calculate percentage with zero guard""" | |
| try: | |
| return round(100 * n / d, 1) if d else 0.0 | |
| except (TypeError, ZeroDivisionError): | |
| return 0.0 | |
| def as_int(x, default=0): | |
| """Convert to integer with fallback""" | |
| try: | |
| return int(x) | |
| except (ValueError, TypeError): | |
| return default | |
| def as_float(x, default=0.0): | |
| """Convert to float with fallback""" | |
| try: | |
| return float(x) | |
| except (ValueError, TypeError): | |
| return default |