From 8c6a7c4071bd4a3cc05412a2f469a0d8da81517b Mon Sep 17 00:00:00 2001 From: "2569718930@qq.com" <2569718930@qq.com> Date: Sat, 18 Apr 2026 16:15:34 +0800 Subject: [PATCH] Fix Russia station parser to read latest archive row --- src/data_collection/russia_station_sources.py | 2 +- tests/test_russia_station_sources.py | 21 +++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/data_collection/russia_station_sources.py b/src/data_collection/russia_station_sources.py index 441db870..873186d7 100644 --- a/src/data_collection/russia_station_sources.py +++ b/src/data_collection/russia_station_sources.py @@ -175,7 +175,7 @@ class RussiaStationSourceMixin: return None pair_count = min(len(time_rows), len(data_rows)) - 1 - for idx in range(pair_count): + for idx in range(pair_count - 1, -1, -1): time_row = time_rows[idx + 1] data_row = data_rows[idx + 1] if len(time_row) < 2 or len(data_row) < 6: diff --git a/tests/test_russia_station_sources.py b/tests/test_russia_station_sources.py index a96f89aa..c8451e71 100644 --- a/tests/test_russia_station_sources.py +++ b/tests/test_russia_station_sources.py @@ -38,3 +38,24 @@ def test_fetch_moscow_official_nearby_keeps_nearest_ten_station_rows(): assert rows[0]["station_code"] == "27524" assert rows[1]["station_code"] == "27500" assert all(row["distance_km"] is not None for row in rows) + + +def test_russia_weather_archive_parser_uses_latest_valid_row(): + html = """ + + + + +
hourdate
0911.04
2117.04
+ + + + +
abcdcloudtemp
xxxxx+4.2
xxxxx+5.8
+ """ + + parsed = RussiaStationSourceMixin()._ru_parse_station_current_from_weather_html(html) + + assert parsed["temp_c"] == 5.8 + assert parsed["raw_hour"] == "21" + assert parsed["raw_day_month"] == "17.04"