]> git.scottworley.com Git - paperdoorknob/commitdiff
Use view=flat to get whole threads at once
authorScott Worley <scottworley@scottworley.com>
Thu, 28 Dec 2023 23:19:37 +0000 (15:19 -0800)
committerScott Worley <scottworley@scottworley.com>
Thu, 28 Dec 2023 23:19:37 +0000 (15:19 -0800)
glowfic.py
paperdoorknob.py
paperdoorknob_test.py

index d1966cae628267177b08789aaf8714c81c01f6d3..573050872d3d3d3ef6e5647c02dcb4f238e65e21 100644 (file)
@@ -8,6 +8,7 @@
 from abc import ABC, abstractmethod
 from dataclasses import dataclass
 import itertools
 from abc import ABC, abstractmethod
 from dataclasses import dataclass
 import itertools
+from urllib.parse import parse_qsl, urlencode, urlparse, urlunparse
 
 from typing import Iterable
 
 
 from typing import Iterable
 
@@ -18,6 +19,23 @@ from images import ImageStore
 from texify import Texifier
 
 
 from texify import Texifier
 
 
+def _removeViewFromURL(url: str) -> str:
+    u = urlparse(url)
+    old_qs = parse_qsl(u.query)
+    new_qs = [(k, v) for k, v in old_qs if k != 'view']
+    return urlunparse(u._replace(query=urlencode(new_qs)))
+
+
+def nonFlatURL(url: str) -> str:
+    return _removeViewFromURL(url)
+
+
+def flatURL(url: str) -> str:
+    u = urlparse(_removeViewFromURL(url))
+    qs = parse_qsl(u.query) + [('view', 'flat')]
+    return urlunparse(u._replace(query=urlencode(qs)))
+
+
 @dataclass(frozen=True)
 class Chunk:
     icon: str | None
 @dataclass(frozen=True)
 class Chunk:
     icon: str | None
index 5e5747c90e5c6483754e23d2a2d51014f656a312..4ee4dbc2a0fca7208d62ec9fd8c6e212087c5062 100644 (file)
@@ -8,7 +8,7 @@
 from bs4 import BeautifulSoup
 
 from args import spec_from_commandline_args
 from bs4 import BeautifulSoup
 
 from args import spec_from_commandline_args
-from glowfic import chunkDOMs, makeChunk
+from glowfic import chunkDOMs, flatURL, makeChunk
 from spec import Spec
 
 
 from spec import Spec
 
 
@@ -27,7 +27,8 @@ def process(spec: Spec) -> None:
                           spec.geometry.encode('UTF-8') +
                           b']{geometry}\n')
     spec.texout.write(b'\\begin{document}\n')
                           spec.geometry.encode('UTF-8') +
                           b']{geometry}\n')
     spec.texout.write(b'\\begin{document}\n')
-    html = parse(spec.htmlfilter(spec.fetcher.fetch(spec.url)))
+    url = flatURL(spec.url)
+    html = parse(spec.htmlfilter(spec.fetcher.fetch(url)))
     for r in chunkDOMs(html):
         spec.domfilter(r)
         chunk = makeChunk(r, spec.images)
     for r in chunkDOMs(html):
         spec.domfilter(r)
         chunk = makeChunk(r, spec.images)
index 4711fcdfb01f021d8f833a79e9d1496a1b25ff3c..2787287eb8575145f15d0679582bda386edfe546 100644 (file)
@@ -112,7 +112,7 @@ class TestProcessFromFakeFetcher(BaseTestProcess, unittest.TestCase):
 
     def fetcher(self) -> Fetcher:
         with open('testdata/this-is-glowfic.html', 'rb') as f:
 
     def fetcher(self) -> Fetcher:
         with open('testdata/this-is-glowfic.html', 'rb') as f:
-            return FakeFetcher({'fic': f.read(9999)})
+            return FakeFetcher({'fic?view=flat': f.read(9999)})
 
 
 if __name__ == '__main__':
 
 
 if __name__ == '__main__':