From 58eb036e5a53afdafdec0b8adc16d9e589976250 Mon Sep 17 00:00:00 2001 From: Dima Gerasimov Date: Wed, 8 May 2019 21:09:06 +0100 Subject: [PATCH] simplify provider --- ci.sh | 10 ---------- goodreads/__init__.py | 20 ++++++++++++++------ goodreads/__main__.py | 9 --------- run | 6 ------ 4 files changed, 14 insertions(+), 31 deletions(-) delete mode 100755 ci.sh delete mode 100644 goodreads/__main__.py delete mode 100755 run diff --git a/ci.sh b/ci.sh deleted file mode 100755 index 0546b95..0000000 --- a/ci.sh +++ /dev/null @@ -1,10 +0,0 @@ -#!/bin/bash - -cd "$(this_dir)" || exit - -. ~/bash_ci - -ci_run mypy goodreads -ci_run pylint -E goodreads - -ci_report_errors diff --git a/goodreads/__init__.py b/goodreads/__init__.py index 6cca4e4..09a7aa8 100644 --- a/goodreads/__init__.py +++ b/goodreads/__init__.py @@ -1,13 +1,16 @@ -import os +from pathlib import Path +from typing import List, Dict, NamedTuple +from datetime import datetime + from xml.dom.minidom import parseString # type: ignore -BPATH = "/L/backups/goodreads" +BPATH = Path("/L/backups/goodreads") # TODO might be useful to keep track of updates?... # then I need some sort of system to store diffs in generic way... # althogh... coud use same mechanism as for filtering -def get_last() -> str: - return max(sorted([os.path.join(BPATH, f) for f in os.listdir(BPATH) if f.endswith('.xmll')])) +def get_last() -> Path: + return max(sorted(BPATH.glob('*.xmll'))) _SP = '' @@ -22,6 +25,7 @@ def get_reviews(): xmls.append(parseString(xx + _SP)) return xmls + def get_books(): books = [] for review in get_reviews(): @@ -70,12 +74,11 @@ def get_books(): books.append(book) return books -from typing import List, Dict, NamedTuple -from datetime import datetime class Event(NamedTuple): dt: datetime summary: str + eid: str def _parse_date(s: str) -> datetime: @@ -90,6 +93,11 @@ def get_events(): events.append(Event( dt=added, summary=f'Added book "{title}"', # TODO shelf? + eid=b['id'], )) # TODO finished? other updates? return sorted(events, key=lambda e: e.dt) + + +def test(): + assert len(get_events()) > 20 diff --git a/goodreads/__main__.py b/goodreads/__main__.py deleted file mode 100644 index f38c577..0000000 --- a/goodreads/__main__.py +++ /dev/null @@ -1,9 +0,0 @@ -from goodreads import get_events - -def main(): - for e in get_events(): - print(e) - - -if __name__ == '__main__': - main() diff --git a/run b/run deleted file mode 100755 index d610c53..0000000 --- a/run +++ /dev/null @@ -1,6 +0,0 @@ -#!/bin/bash -set -eu - -cd "$(dirname "$0")" - -python3 -m goodreads