build-small-hackathon/hackathon-advisor
16
1"""Shared, dependency-free text and timestamp helpers.2 3Kept stdlib-only so it is safe to import from any runtime (Modal containers,4embedding subprocesses) and from the export modules without creating cycles.5"""6 7from __future__ import annotations8 9from datetime import datetime, timezone10from typing import Any11 12 13def clean(value: Any) -> str:14 """Collapse whitespace to single spaces; ``None`` becomes an empty string."""15 if value is None:16 return ""17 return " ".join(str(value).split())18 19 20def list_of_dicts(value: Any) -> list[dict[str, Any]]:21 """Return only the ``dict`` items of ``value`` when it is a list, else ``[]``."""22 if not isinstance(value, list):23 return []24 return [item for item in value if isinstance(item, dict)]25 26 27def utc_now() -> str:28 """Current UTC time as an ISO-8601 string at second resolution."""29 return datetime.now(timezone.utc).isoformat(timespec="seconds")30 