From: Scott Worley Date: Fri, 24 Nov 2023 04:04:59 +0000 (-0800) Subject: entries() convenience method X-Git-Url: http://git.scottworley.com/paperdoorknob/commitdiff_plain/55958ec0820a10472e5091b105d730fa38172390?hp=a0d30541ee9349b8c62200c9aa6d4dbb2873fccb entries() convenience method --- diff --git a/paperdoorknob.py b/paperdoorknob.py index 0c6ec85..6cc76a2 100644 --- a/paperdoorknob.py +++ b/paperdoorknob.py @@ -6,6 +6,7 @@ from argparse import ArgumentParser +import itertools import os.path from typing import Iterable @@ -33,6 +34,9 @@ class Post: assert all(isinstance(r, Tag) for r in replies) return replies + def entries(self) -> Iterable[Tag]: + return itertools.chain([self.text()], self.replies()) + def command_line_parser() -> ArgumentParser: parser = ArgumentParser(prog='paperdoorknob', description='Print glowfic') diff --git a/paperdoorknob_test.py b/paperdoorknob_test.py index 7c48607..5fe1779 100644 --- a/paperdoorknob_test.py +++ b/paperdoorknob_test.py @@ -102,6 +102,8 @@ class TestFetch(unittest.TestCase): self.assertEqual(post.text().text.strip(), "This is glowfic") self.assertEqual([r.text.strip() for r in post.replies()], ["You sure?", "Pretty sure."]) + self.assertEqual([r.text.strip() for r in post.entries()], + ["This is glowfic", "You sure?", "Pretty sure."]) def testFetchErrors(self) -> None: with requests.session() as s: