Complete stage 0 source research

This commit is contained in:
ik
2026-09-02 19:52:32 +07:00
commit a6f91a1329
9 changed files with 1096 additions and 0 deletions
+40
View File
@@ -0,0 +1,40 @@
<!doctype html>
<html lang="de">
<body>
<!-- Reduced and anonymized from the public RF4 records DOM contract. -->
<div class="records flex_table">
<div class="row header">
<div class="col fish">Fisch</div>
<div class="col weight">Gewicht</div>
<div class="col location">Gewässer</div>
<div class="col bait">Kunstköder</div>
<div class="col gamername">Spieler</div>
<div class="col data">Datum</div>
</div>
<div class="rows">
<div class="row">
<div class="records_subtable flex_table">
<div class="row header">
<div class="col fish"><div class="text">Hecht</div></div>
<div class="col weight">27.902&nbsp;kg</div>
<div class="col location">Testsee</div>
<div class="col bait"><div class="bait_icon" title="Testköder 01"></div></div>
<div class="col gamername">Spieler A</div>
<div class="col data">11.02.26</div>
</div>
<div class="rows">
<div class="row">
<div class="col fish"></div>
<div class="col weight">2 519.264&nbsp;kg</div>
<div class="col location">Testmeer</div>
<div class="col bait"><div class="bait_icon" title="Testköder 02"></div></div>
<div class="col gamername">Spieler B</div>
<div class="col data">03.05.26</div>
</div>
</div>
</div>
</div>
</div>
</div>
</body>
</html>
+47
View File
@@ -0,0 +1,47 @@
from datetime import date
from pathlib import Path
import unittest
from rf4_research.records import RecordsParseError, parse_records_html, parse_weight_g
FIXTURE = Path(__file__).parent / "fixtures" / "records_ru_sample.html"
class RecordsParserTests(unittest.TestCase):
def test_parses_group_header_and_nested_records(self) -> None:
records = parse_records_html(
FIXTURE.read_text(encoding="utf-8"),
region="ru",
category="records",
source_url="https://rf4game.de/records/region/RU/",
today=date(2026, 9, 2),
)
self.assertEqual(len(records), 2)
self.assertEqual(records[0].fish, "Hecht")
self.assertEqual(records[0].weight_g, 27_902)
self.assertEqual(records[0].bait, "Testköder 01")
self.assertEqual(records[1].fish, "Hecht")
self.assertEqual(records[1].weight_g, 2_519_264)
self.assertEqual(records[1].record_date, date(2026, 5, 3))
def test_rejects_changed_column_contract(self) -> None:
html = FIXTURE.read_text(encoding="utf-8").replace(
'class="col data"', 'class="col changed"', 1
)
with self.assertRaisesRegex(RecordsParseError, "records columns changed"):
parse_records_html(
html,
region="RU",
category="records",
source_url="fixture://changed",
)
def test_weight_units_are_normalized_to_grams(self) -> None:
self.assertEqual(parse_weight_g("423 g"), 423)
self.assertEqual(parse_weight_g("8.023 kg"), 8_023)
if __name__ == "__main__":
unittest.main()