diff --git a/calls/__init__.py b/calls/__init__.py index d620b76..587d71d 100644 --- a/calls/__init__.py +++ b/calls/__init__.py @@ -1,10 +1,13 @@ -BPATH = "/L/backups/smscalls" -import re -import pytz -_RE = re.compile(r'calls-\d+.xml') - +import os +from pathlib import Path from typing import Dict, List, NamedTuple, Iterator, Iterable from datetime import datetime +import pytz + +from lxml import etree # type: ignore + +BPATH = Path("/L/backups/smscalls") + class Call(NamedTuple): dt: datetime @@ -17,7 +20,6 @@ class Call(NamedTuple): def _extract_calls(fname: str) -> Iterator[Call]: - from lxml import etree # type: ignore tr = etree.parse(fname) for cxml in tr.findall('call'): # TODO we've got local tz herer, not sure if useful.. @@ -31,9 +33,8 @@ def _extract_calls(fname: str) -> Iterator[Call]: ) def get_calls(): - import os calls: Dict[datetime, Call] = {} - for n in sorted([x for x in os.listdir(BPATH) if _RE.match(x)]): + for n in sorted(BPATH.glob('calls-*.xml')): # for c in _extract_calls(os.path.join(BPATH, n)): # cc = calls.get(c.dt, None) # if cc is not None and cc != c: @@ -41,3 +42,7 @@ def get_calls(): calls.update({c.dt: c for c in _extract_calls(os.path.join(BPATH, n))}) # always replacing with latter is good, we get better contact names return sorted(calls.values(), key=lambda c: c.dt) + + +def test(): + assert len(get_calls()) > 10 diff --git a/calls/__main__.py b/calls/__main__.py deleted file mode 100644 index 211cde4..0000000 --- a/calls/__main__.py +++ /dev/null @@ -1,4 +0,0 @@ -from calls import get_calls - -for c in get_calls(): - print(c) diff --git a/ci.sh b/ci.sh deleted file mode 100755 index 8309482..0000000 --- a/ci.sh +++ /dev/null @@ -1,10 +0,0 @@ -#!/bin/bash - -cd "$(this_dir)" || exit - -. ~/bash_ci - -ci_run mypy calls -ci_run pylint -E calls - -ci_report_errors diff --git a/run b/run deleted file mode 100755 index 4f3de36..0000000 --- a/run +++ /dev/null @@ -1,6 +0,0 @@ -#!/bin/bash -set -eu - -cd "$(dirname "$0")" - -python3 -m calls