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"