rss module: prettify & reorganize to allow for easily adding extra modules
This commit is contained in:
parent
92cf375480
commit
63d4198fd9
6 changed files with 66 additions and 58 deletions
|
@ -1,29 +1,11 @@
|
|||
from itertools import chain
|
||||
from typing import List, Dict
|
||||
|
||||
from ._rss import Subscription
|
||||
|
||||
from . import feedbin
|
||||
from . import feedly
|
||||
# TODO google reader?
|
||||
'''
|
||||
Unified RSS data, merged from different services I used historically
|
||||
'''
|
||||
from typing import Iterable
|
||||
from .common import Subscription, compute_subscriptions
|
||||
|
||||
|
||||
def get_all_subscriptions() -> List[Subscription]:
|
||||
"""
|
||||
Keeps track of everything I ever subscribed to. It's useful to keep track of unsubscribed too
|
||||
so you don't try to subscribe again (or at least take into account why you unsubscribed before)
|
||||
"""
|
||||
states = {}
|
||||
states.update(feedly.get_states())
|
||||
states.update(feedbin.get_states())
|
||||
by_url: Dict[str, Subscription] = {}
|
||||
for _, feeds in sorted(states.items()):
|
||||
for f in feeds:
|
||||
if f.url not in by_url:
|
||||
by_url[f.url] = f
|
||||
res = []
|
||||
last = {x.url: x for x in max(states.items())[1]}
|
||||
for u, x in sorted(by_url.items()):
|
||||
present = u in last
|
||||
res.append(x._replace(subscribed=present))
|
||||
return res
|
||||
def subscriptions() -> Iterable[Subscription]:
|
||||
from . import feedbin, feedly
|
||||
# TODO google reader?
|
||||
yield from compute_subscriptions(feedbin.states(), feedly.states())
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue