support synthetic exports

This commit is contained in:
Dima Gerasimov 2020-02-24 17:30:58 +01:00
parent fe0521b6dc
commit f9fbef1b87

View file

@ -9,11 +9,13 @@ from typing import Any, Dict, Iterator, NamedTuple
import pytz import pytz
import dataset # type: ignore import dataset # type: ignore
from .common import get_files
from mycfg import paths from mycfg import paths
Row = Dict[str, Any] Row = Dict[str, Any]
class Saved(NamedTuple): class Saved(NamedTuple):
row: Row row: Row
@ -22,7 +24,6 @@ class Saved(NamedTuple):
ts = int(self.row['time']) / 1000 ts = int(self.row['time']) / 1000
return datetime.fromtimestamp(ts, tz=pytz.utc) return datetime.fromtimestamp(ts, tz=pytz.utc)
@property @property
def uid(self) -> str: def uid(self) -> str:
return self.row['itemid'] return self.row['itemid']
@ -40,8 +41,12 @@ class Saved(NamedTuple):
return f'https://news.ycombinator.com/item?id={self.uid}' return f'https://news.ycombinator.com/item?id={self.uid}'
def _last_export():
return max(get_files(paths.materialistic.export_path, glob='*.db'))
def raw() -> Iterator[Row]: def raw() -> Iterator[Row]:
db = dataset.connect('sqlite:///' + str(max(paths.materialistic.export_path.glob('*.db')))) db = dataset.connect('sqlite:///' + str(_last_export))
st = db['saved'] st = db['saved']
# TODO wonder if it's 'save time'? # TODO wonder if it's 'save time'?
yield from st.all(order_by='time') yield from st.all(order_by='time')