simplify provider

This commit is contained in:
Dima Gerasimov 2019-05-08 20:42:14 +01:00
parent 36fbb3aa69
commit 3b525b39aa
4 changed files with 13 additions and 28 deletions

View file

@ -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

View file

@ -1,4 +0,0 @@
from calls import get_calls
for c in get_calls():
print(c)