From 585206f72d19e7ccadeba4236c43ce0d726ba328 Mon Sep 17 00:00:00 2001 From: Dima Gerasimov Date: Sun, 1 Dec 2019 13:48:38 +0000 Subject: [PATCH] use my_configuration for imdb/youtube --- my/media/imdb.py | 16 +++++++--------- my/media/youtube.py | 15 +++++++++++++-- 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/my/media/imdb.py b/my/media/imdb.py index ce47c51..f1b6a2c 100644 --- a/my/media/imdb.py +++ b/my/media/imdb.py @@ -4,15 +4,13 @@ import json from datetime import datetime from typing import Iterator, List, NamedTuple -from ..paths import BACKUPS +from ..common import get_files +# TODO eh. rename to my_cfg? easier to type +from my_configuration import paths -BDIR = BACKUPS / 'imdb' - - -def get_last(): - # TODO wonder where did json come from.. - return max(BDIR.glob('*.csv')) +def _get_last(): + return max(get_files(paths.imdb.export_path, glob='*.csv')) class Movie(NamedTuple): @@ -22,14 +20,14 @@ class Movie(NamedTuple): def iter_movies() -> Iterator[Movie]: - last = get_last() + last = _get_last() with last.open() as fo: reader = csv.DictReader(fo) for i, line in enumerate(reader): # TODO extract directors?? title = line['Title'] - rating = line['You rated'] + rating = int(line['You rated']) createds = line['created'] created = datetime.strptime(createds, '%a %b %d %H:%M:%S %Y') # TODO const?? diff --git a/my/media/youtube.py b/my/media/youtube.py index d0ebcc2..5f58b98 100755 --- a/my/media/youtube.py +++ b/my/media/youtube.py @@ -6,7 +6,17 @@ from pathlib import Path from kython.ktakeout import TakeoutHTMLParser from kython.kompress import open as kopen -BDIR = Path("/L/backups/takeout/karlicoss_gmail_com/") +from ..common import get_files + +from my_configuration import paths + + +def _get_last_takeout(): + # TODO FIXME might be a good idea to merge across multiple taekouts... + # perhaps even a special takeout module that deals with all of this automatically? + # e.g. accumulate, filter and maybe report useless takeouts? + return max(get_files(paths.google.takeout_path, glob='*.zip')) + class Watched(NamedTuple): url: str @@ -17,8 +27,9 @@ class Watched(NamedTuple): def eid(self) -> str: return f'{self.url}-{self.when.isoformat()}' + def get_watched(): - last = max(BDIR.glob('*.zip')) + last = _get_last_takeout() watches: List[Watched] = [] def cb(dt, url, title):