From 55958ec0820a10472e5091b105d730fa38172390 Mon Sep 17 00:00:00 2001 From: Scott Worley Date: Thu, 23 Nov 2023 20:04:59 -0800 Subject: [PATCH 1/1] entries() convenience method --- paperdoorknob.py | 4 ++++ paperdoorknob_test.py | 2 ++ 2 files changed, 6 insertions(+) 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: -- 2.44.1