-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.py
51 lines (40 loc) · 1.25 KB
/
utils.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# Utility functions for the Wisconsin Weather API
import logging
from typing import Optional, Dict, Any
def configure_logging() -> logging.Logger:
"""
Configure and return a standard logger for the application.
Returns:
logging.Logger: Configured logger instance
"""
logging.basicConfig(
level=logging.INFO,
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s'
)
return logging.getLogger(__name__)
def validate_station_id(station_id: str) -> bool:
"""
Validate the format of a station ID.
Args:
station_id (str): Station identifier to validate
Returns:
bool: Whether the station ID is valid
"""
# Add your specific validation logic here
# Example: Check length, format, etc.
return station_id is not None and len(station_id) > 0
def safe_get(
data: Dict[str, Any],
key: str,
default: Optional[Any] = None
) -> Optional[Any]:
"""
Safely retrieve a value from a dictionary.
Args:
data (dict): Source dictionary
key (str): Key to retrieve
default (Optional[Any]): Default value if key not found
Returns:
Optional[Any]: Retrieved value or default
"""
return data.get(key, default)