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
029fa3ae84
commit
f4214807a3
6 changed files with 81 additions and 65 deletions
|
@ -1,14 +1,15 @@
|
|||
"""
|
||||
Feedly RSS reader
|
||||
"""
|
||||
|
||||
from my.config import feedly as config
|
||||
|
||||
from datetime import datetime, timezone
|
||||
import json
|
||||
from pathlib import Path
|
||||
from typing import Iterable, Sequence
|
||||
from typing import Iterator, Sequence
|
||||
|
||||
from ..core.common import listify, get_files
|
||||
from my.core import get_files
|
||||
from .common import Subscription, SubscriptionState
|
||||
|
||||
|
||||
|
@ -16,13 +17,12 @@ def inputs() -> Sequence[Path]:
|
|||
return get_files(config.export_path)
|
||||
|
||||
|
||||
@listify
|
||||
def parse_file(f: Path):
|
||||
def parse_file(f: Path) -> Iterator[Subscription]:
|
||||
raw = json.loads(f.read_text())
|
||||
for r in raw:
|
||||
# err, some even don't have website..
|
||||
rid = r['id']
|
||||
website = r.get('website', rid) # meh
|
||||
website = r.get('website', rid) # meh
|
||||
yield Subscription(
|
||||
created_at=None,
|
||||
title=r['title'],
|
||||
|
@ -31,9 +31,9 @@ def parse_file(f: Path):
|
|||
)
|
||||
|
||||
|
||||
def states() -> Iterable[SubscriptionState]:
|
||||
def states() -> Iterator[SubscriptionState]:
|
||||
for f in inputs():
|
||||
dts = f.stem.split('_')[-1]
|
||||
dt = datetime.strptime(dts, '%Y%m%d%H%M%S').replace(tzinfo=timezone.utc)
|
||||
subs = parse_file(f)
|
||||
subs = list(parse_file(f))
|
||||
yield dt, subs
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue