HPI/my/browser/active_browser.py
Dima Gerasimov 2b0f92c883 my.core: deprecate Path/dataclass imports from my.core during type checking
runtime still works for backwards compatibility
2024-08-16 10:22:29 +01:00

52 lines
1.2 KiB
Python

"""
Parses active browser history by backing it up with [[http://github.com/seanbreckenridge/sqlite_backup][sqlite_backup]]
"""
REQUIRES = ["browserexport", "sqlite_backup"]
from dataclasses import dataclass
from my.config import browser as user_config
from my.core import Paths
@dataclass
class config(user_config.active_browser):
# paths to sqlite database files which you use actively
# to read from. For example:
# from browserexport.browsers.all import Firefox
# export_path = Firefox.locate_database()
export_path: Paths
from pathlib import Path
from typing import Sequence, Iterator
from my.core import get_files, Stats, make_logger
from browserexport.merge import read_visits, Visit
from sqlite_backup import sqlite_backup
logger = make_logger(__name__)
from .common import _patch_browserexport_logs
_patch_browserexport_logs(logger.level)
def inputs() -> Sequence[Path]:
return get_files(config.export_path)
def history() -> Iterator[Visit]:
for ad in inputs():
conn = sqlite_backup(ad)
assert conn is not None
try:
yield from read_visits(conn)
finally:
conn.close()
def stats() -> Stats:
from my.core import stat
return {**stat(history)}