From: Scott Worley Date: Fri, 26 Jan 2024 02:09:18 +0000 (-0800) Subject: next_thread should be an absolute URL X-Git-Url: http://git.scottworley.com/paperdoorknob/commitdiff_plain/fc2aaa75baff15d201153efeeda0c4c5898e4822 next_thread should be an absolute URL --- diff --git a/glowfic.py b/glowfic.py index 81a5342..9d863c8 100644 --- a/glowfic.py +++ b/glowfic.py @@ -7,7 +7,7 @@ from dataclasses import dataclass import itertools -from urllib.parse import parse_qsl, urlencode, urlparse, urlunparse +from urllib.parse import parse_qsl, urlencode, urljoin, urlparse, urlunparse from typing import Iterable @@ -63,7 +63,7 @@ class Thread: for a in c.findChildren('a'): if 'Next Post' in a.text and 'href' in a.attrs and isinstance( a.attrs['href'], str): - return a.attrs['href'] + return urljoin(spec.url, a.attrs['href']) return None spec.log('Fetching HTML...\r') diff --git a/glowfic_test.py b/glowfic_test.py index 22eea25..bd26e3c 100644 --- a/glowfic_test.py +++ b/glowfic_test.py @@ -103,7 +103,7 @@ class TestThread(unittest.TestCase): ''')) self.assertEqual(t.title(), 'Teh Story!') - def testNextThread(self) -> None: + def testNextThreadRelative(self) -> None: t = Thread(spec_for_testing(b'''
@@ -113,7 +113,19 @@ class TestThread(unittest.TestCase):
The "post"
''')) - self.assertEqual(t.next_thread(), '/posts/4567') + self.assertEqual(t.next_thread(), 'https://fake/posts/4567') + + def testNextThreadAbsolute(self) -> None: + t = Thread(spec_for_testing(b''' + +
+
Next Post »
+
« Previous Post
+
+
+
The "post"
+ ''')) + self.assertEqual(t.next_thread(), 'https://elsewhere/posts/4567') if __name__ == '__main__':