feat: introduce WundergroundSourceMixin for fetching, parsing, and extracting weather observation data from Wunderground.

This commit is contained in:
2569718930@qq.com
2026-03-25 19:28:35 +08:00
parent 7de31ec429
commit ab5c5cfb23
+11 -11
View File
@@ -193,6 +193,17 @@ class WundergroundSourceMixin:
text = str(raw or "").strip()
if not text:
return None
try:
parsed = datetime.strptime(text, "%Y-%m-%dT%H:%M:%S%z")
return parsed.astimezone(timezone.utc).isoformat()
except Exception:
pass
try:
parsed = datetime.strptime(text, "%Y-%m-%d %H:%M:%S")
parsed = parsed.replace(tzinfo=timezone(timedelta(seconds=utc_offset_seconds)))
return parsed.astimezone(timezone.utc).isoformat()
except Exception:
return None
@staticmethod
def _wu_parse_history_time(raw: Any, utc_offset_seconds: int) -> Optional[str]:
@@ -296,17 +307,6 @@ class WundergroundSourceMixin:
if len(parsed) > len(best):
best = parsed
return best
try:
parsed = datetime.strptime(text, "%Y-%m-%dT%H:%M:%S%z")
return parsed.astimezone(timezone.utc).isoformat()
except Exception:
pass
try:
parsed = datetime.strptime(text, "%Y-%m-%d %H:%M:%S")
parsed = parsed.replace(tzinfo=timezone(timedelta(seconds=utc_offset_seconds)))
return parsed.astimezone(timezone.utc).isoformat()
except Exception:
return None
@staticmethod
def _wu_find_current_observation_block(