core.common: move listify to core.utils.itertools, use better typing annotations for it
also some minor refactoring of my.rss
This commit is contained in:
parent
c64d7f5b67
commit
66c08a6c80
6 changed files with 81 additions and 65 deletions
|
@ -2,24 +2,22 @@
|
|||
Feedbin RSS reader
|
||||
"""
|
||||
|
||||
from my.config import feedbin as config
|
||||
|
||||
import json
|
||||
from pathlib import Path
|
||||
from typing import Sequence
|
||||
from typing import Iterator, Sequence
|
||||
|
||||
from my.core.common import listify, get_files
|
||||
from my.core import get_files, stat, Stats
|
||||
from my.core.compat import fromisoformat
|
||||
from .common import Subscription
|
||||
from .common import Subscription, SubscriptionState
|
||||
|
||||
from my.config import feedbin as config
|
||||
|
||||
|
||||
def inputs() -> Sequence[Path]:
|
||||
return get_files(config.export_path)
|
||||
|
||||
|
||||
import json
|
||||
|
||||
@listify
|
||||
def parse_file(f: Path):
|
||||
def parse_file(f: Path) -> Iterator[Subscription]:
|
||||
raw = json.loads(f.read_text())
|
||||
for r in raw:
|
||||
yield Subscription(
|
||||
|
@ -30,19 +28,14 @@ def parse_file(f: Path):
|
|||
)
|
||||
|
||||
|
||||
from typing import Iterable
|
||||
from .common import SubscriptionState
|
||||
def states() -> Iterable[SubscriptionState]:
|
||||
def states() -> Iterator[SubscriptionState]:
|
||||
for f in inputs():
|
||||
# TODO ugh. depends on my naming. not sure if useful?
|
||||
dts = f.stem.split('_')[-1]
|
||||
dt = fromisoformat(dts)
|
||||
subs = parse_file(f)
|
||||
subs = list(parse_file(f))
|
||||
yield dt, subs
|
||||
|
||||
|
||||
def stats():
|
||||
from more_itertools import ilen, last
|
||||
return {
|
||||
'subscriptions': ilen(last(states())[1])
|
||||
}
|
||||
def stats() -> Stats:
|
||||
return stat(states)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue