general: use less explicit kompress boilerplate in modules
now get_files/kompress library can handle it transparently
This commit is contained in:
parent
c63e80ce94
commit
8c2d1c9463
9 changed files with 14 additions and 19 deletions
|
@ -146,12 +146,11 @@ class TakeoutHTMLParser(HTMLParser):
|
|||
|
||||
|
||||
def read_html(tpath: Path, file: str) -> Iterable[Parsed]:
|
||||
from ...core.kompress import kopen
|
||||
results: List[Parsed] = []
|
||||
def cb(dt: datetime, url: Url, title: Title) -> None:
|
||||
results.append((dt, url, title))
|
||||
parser = TakeoutHTMLParser(callback=cb)
|
||||
with kopen(tpath, file) as fo:
|
||||
with (tpath / file).open() as fo:
|
||||
data = fo.read()
|
||||
parser.feed(data)
|
||||
return results
|
||||
|
|
|
@ -94,10 +94,9 @@ def events(disable_takeout_cache: bool = DISABLE_TAKEOUT_CACHE) -> CacheResults:
|
|||
for path in reversed(inputs()):
|
||||
with ExitStack() as exit_stack:
|
||||
if config._use_zippath:
|
||||
from my.core.kompress import ZipPath
|
||||
# for later takeouts it's just 'Takeout' dir,
|
||||
# but for older (pre 2015) it contains email/date in the subdir name
|
||||
results = tuple(cast(Sequence[Path], ZipPath(path).iterdir()))
|
||||
results = tuple(cast(Sequence[Path], path.iterdir()))
|
||||
else:
|
||||
results = exit_stack.enter_context(match_structure(path, expected=EXPECTED, partial=True))
|
||||
for m in results:
|
||||
|
|
|
@ -23,8 +23,6 @@ config = make_config(google)
|
|||
from pathlib import Path
|
||||
from typing import Optional, Iterable
|
||||
|
||||
from ...core.kompress import kexists
|
||||
|
||||
|
||||
def get_takeouts(*, path: Optional[str]=None) -> Iterable[Path]:
|
||||
"""
|
||||
|
@ -33,7 +31,7 @@ def get_takeouts(*, path: Optional[str]=None) -> Iterable[Path]:
|
|||
# TODO FIXME zip is not great..
|
||||
# allow a lambda expression? that way the user could restrict it
|
||||
for takeout in get_files(config.takeout_path, glob='*.zip'):
|
||||
if path is None or kexists(takeout, path):
|
||||
if path is None or (takeout / path).exists():
|
||||
yield takeout
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue