get rid of callbacks in takeout processing interface

This commit is contained in:
Dima Gerasimov 2020-04-24 17:01:06 +01:00
parent 810fe21839
commit d1aa4d19dc
4 changed files with 40 additions and 25 deletions

View file

@ -2,10 +2,7 @@
from datetime import datetime
from typing import NamedTuple, List
# TODO ugh. reuse it in mypkg/releaste takeout parser separately?
from ..kython.ktakeout import TakeoutHTMLParser
from ..kython.kompress import kopen
from ..kython.ktakeout import read_html
from ..takeout import get_last_takeout
@ -26,15 +23,9 @@ def get_watched():
last = get_last_takeout(path=path)
watches: List[Watched] = []
def cb(dt, url, title):
for dt, url, title in read_html(last, path):
watches.append(Watched(url=url, title=title, when=dt))
parser = TakeoutHTMLParser(cb)
with kopen(last, path) as fo:
dd = fo.read().decode('utf8')
parser.feed(dd)
# TODO hmm they already come sorted.. wonder if should just rely on it..
return list(sorted(watches, key=lambda e: e.when))