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 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
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
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)
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__':