def test_kopen(tmp_path: Path) -> None: "Plaintext handled transparently" assert kopen(tmp_path / 'file' ).read() == 'just plaintext' assert kopen(tmp_path / 'file.xz').read() == 'compressed text' "For zips behaviour is a bit different (not sure about all this, tbh...)" assert kopen(tmp_path / 'file.zip', 'path/in/archive').read() == 'data in zip'
def read_browser_history_json(takeout: TakeoutPath) -> Iterable[Visit]: # TODO replace with my.core.kompress after hpi update (or even use some my. function directly?) from my.kython.kompress import kexists, kopen # not sure if this deserves moving to HPI? it's pretty trivial for now spath = 'Takeout/Chrome/BrowserHistory.json' if not kexists(takeout, spath): logger.warning(f"{spath} is not present in {takeout}... skipping") return logger.info('processing %s %s', takeout, spath) # TODO couls also add spath? locator = Loc.file(takeout) # TODO this should be supported by HPI now? j = None with kopen(takeout, spath) as fo: # TODO iterative parser? j = json.load(fo) hist = j['Browser History'] for item in hist: url = item['url'] time = datetime.utcfromtimestamp(item['time_usec'] / 10**6).replace(tzinfo=pytz.utc) # TODO any more interesitng info? yield Visit( url=url, dt=time, locator=locator, debug='Chrome/BrowserHistory.json', )