From: Scott Worley Date: Fri, 24 Nov 2023 03:32:52 +0000 (-0800) Subject: Replies X-Git-Url: http://git.scottworley.com/paperdoorknob/commitdiff_plain/a0d30541ee9349b8c62200c9aa6d4dbb2873fccb?ds=inline;hp=6409066b6abbe205fa64f844a01516f3f3de2553 Replies --- diff --git a/paperdoorknob.py b/paperdoorknob.py index b88c02d..0c6ec85 100644 --- a/paperdoorknob.py +++ b/paperdoorknob.py @@ -7,6 +7,9 @@ from argparse import ArgumentParser import os.path + +from typing import Iterable + from bs4 import BeautifulSoup from bs4.element import Tag import requests @@ -25,6 +28,11 @@ class Post: assert isinstance(text, Tag) return text + def replies(self) -> Iterable[Tag]: + replies = self._html.find_all("div", class_="post-reply") + assert all(isinstance(r, Tag) for r in replies) + return replies + def command_line_parser() -> ArgumentParser: parser = ArgumentParser(prog='paperdoorknob', description='Print glowfic') diff --git a/paperdoorknob_test.py b/paperdoorknob_test.py index 83cf76a..7c48607 100644 --- a/paperdoorknob_test.py +++ b/paperdoorknob_test.py @@ -33,6 +33,14 @@ class FakeGlowficHTTPRequestHandler(BaseHTTPRequestHandler):
This is glowfic
+
+
+ You sure? +
+
+ Pretty sure. +
+
''' self.send_response(self._response_code()) @@ -92,6 +100,8 @@ class TestFetch(unittest.TestCase): post = paperdoorknob.Post(paperdoorknob.fetch( f"http://localhost:{self._port()}", s, TIMEOUT)) self.assertEqual(post.text().text.strip(), "This is glowfic") + self.assertEqual([r.text.strip() for r in post.replies()], + ["You sure?", "Pretty sure."]) def testFetchErrors(self) -> None: with requests.session() as s: