move rss stuff in a separate subpackage

This commit is contained in:
Dima Gerasimov 2020-05-13 21:36:19 +01:00
parent c289fbb872
commit 92cf375480
5 changed files with 4 additions and 4 deletions

29
my/rss/all.py Normal file
View file

@ -0,0 +1,29 @@
from itertools import chain
from typing import List, Dict
from ._rss import Subscription
from . import feedbin
from . import feedly
# TODO google reader?
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