Skip to content
Permalink
Browse files

switch to cachew

  • Loading branch information...
karlicoss committed Jul 27, 2019
1 parent cc459c9 commit ba9d0a24e14225c120bb0b28e636f1fae2528a31
@@ -23,6 +23,7 @@ jobs:
. venv/bin/activate
pip install -r wereyouhere/requirements.txt
pip install 'kython@git+https://github.com/karlicoss/kython.git@master' dateparser typing_extensions logzero
pip install 'cachew@git+https://github.com/karlicoss/cachew.git@master'
# ugh, hug is involved as subprocess and doesn't see virtualenv I gues??
- run:
@@ -2,8 +2,7 @@
from typing import NamedTuple
from pathlib import Path

# TODO binder thing needs to be extracted?
from kython.kcache import Binder
from cachew import DbBinder
from kython.py37 import fromisoformat


@@ -67,8 +66,8 @@ def iter_json():
db = create_engine(f'sqlite:///{db_path}')
engine = db.connect()
meta = MetaData(engine)
binder = Binder(clazz=Visit)
table = Table('visits', meta, *binder.columns)
binder = DbBinder(Visit)
table = Table('visits', meta, *binder.db_columns)
meta.create_all()


@@ -39,7 +39,7 @@ def test_empty(tmp_path):

from sqlalchemy import create_engine, MetaData, exists # type: ignore
from sqlalchemy import Column, Table # type: ignore
from kython.kcache import Binder
from cachew import DbBinder
from wereyouhere.common import DbVisit # TODO ugh. figure out pythonpath


@@ -52,10 +52,10 @@ def _get_stuff(outdir: Path):
# TODO ugh.
import sys
print(sys.path)
binder = Binder(clazz=DbVisit)
binder = DbBinder(DbVisit)

meta = MetaData(engine)
table = Table('visits', meta, *binder.columns)
table = Table('visits', meta, *binder.db_columns)

return engine, binder, table

@@ -7,8 +7,8 @@

from sqlalchemy import create_engine, MetaData # type: ignore
from sqlalchemy import Column, Table # type: ignore
from kython.kcache import Binder
from kython import ichunks

from cachew import DbBinder, ichunks

from .common import Config, get_logger, History, DbVisit

@@ -72,9 +72,9 @@ def iter_visits():
ntf = tempfile.NamedTemporaryFile(delete=False)
tpath = ntf.name
engine = create_engine(f'sqlite:///{tpath}')
binder = Binder(clazz=DbVisit)
binder = DbBinder(DbVisit)
meta = MetaData(engine)
table = Table('visits', meta, *binder.columns)
table = Table('visits', meta, *binder.db_columns)
meta.create_all()

with engine.begin() as trans:
@@ -19,8 +19,7 @@

from wereyouhere.common import PreVisit, get_logger, PathIsh, Tag, Url, Loc


from kython.kcache import make_dbcache, mtime_hash
from cachew import mtime_hash, cachew

# TODO reuse kython, but really, release takeout html parser separately

@@ -160,7 +159,7 @@ def db_pathf(takeout: TakeoutSource) -> Path:
tpath = _path(takeout)
cache_dir = _get_cache_dir()
return cache_dir / (tpath.name + '_' + ident + '.cache')
return make_dbcache(db_pathf, type_=PreVisit, logger=get_logger())
return cachew(db_pathf, cls=PreVisit, logger=get_logger())

@cacheme('google_activity')
def read_google_activity(takeout: TakeoutSource) -> List[PreVisit]:
@@ -11,7 +11,8 @@
from typing import Collection, List, NamedTuple, Dict

from kython import setup_logzero
from kython.kcache import Binder

from cachew import DbBinder

import hug # type: ignore
import hug.types as T # type: ignore
@@ -88,10 +89,10 @@ def get_stuff(): # TODO better name
# TODO how to open read only?
engine = create_engine(f'sqlite:///{db_path}')

binder = Binder(clazz=DbVisit)
binder = DbBinder(DbVisit)

meta = MetaData(engine)
table = Table('visits', meta, *binder.columns)
table = Table('visits', meta, *binder.db_columns)

return engine, binder, table

0 comments on commit ba9d0a2

Please sign in to comment.
You can’t perform that action at this time.