Skip to content

Commit 9fcfb8c

Browse files
committed
minor fixes, don't require a personal tag to exist
1 parent 6c809cc commit 9fcfb8c

File tree

4 files changed

+19
-18
lines changed

4 files changed

+19
-18
lines changed

feedly/data.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
handy getter methods, but otherwise you can just use a .json property to access the
44
raw json passed back by the client.
55
"""
6-
from typing import Any, Dict, Optional
6+
from typing import Any, Dict, Optional, Callable
77
from urllib.parse import quote_plus
88

99
from feedly.protocol import APIClient
1010
from feedly.stream import STREAM_SOURCE_USER, StreamOptions, StreamBase, UserStreamId, EnterpriseStreamId, StreamIdBase, STREAM_SOURCE_ENTERPRISE
11-
11+
import logging
1212

1313
class FeedlyData:
1414
def __init__(self, json:Dict[str,Any], client:APIClient=None):
@@ -184,30 +184,34 @@ def get_enterprise_tags(self, refresh: bool = False) -> Dict[str, 'EnterpriseTag
184184

185185
return self._enterprise_tags
186186

187-
def _get_category_or_tag(self, stream_id:StreamIdBase, cache, factory):
187+
def _get_category_or_tag(self, stream_id:StreamIdBase, cache:Dict[str,Streamable], factory:Callable[[Dict[str,str]], Streamable], auto_create:bool):
188188
if cache:
189189
data = cache.get(stream_id.content_id)
190190
if data:
191191
return data
192-
raise ValueError(f'{id_} does not exist')
192+
193+
if not auto_create:
194+
raise ValueError(f'{stream_id.id} does not exist')
195+
else:
196+
cache.clear()
193197

194198
return factory({'id': stream_id.id}, self._client)
195199

196200
def get_category(self, name:str):
197201
id_ = UserStreamId(parts=[STREAM_SOURCE_USER, self.id, 'category', name])
198202

199-
return self._get_category_or_tag(id_, self._categories, UserCategory)
203+
return self._get_category_or_tag(id_, self._categories, UserCategory, False)
200204

201205
def get_tag(self, name:str) -> 'UserTag':
202206
id_ = UserStreamId(parts=[STREAM_SOURCE_USER, self.id, 'tag', name])
203207

204-
return self._get_category_or_tag(id_, self._tags, UserTag)
208+
return self._get_category_or_tag(id_, self._tags, UserTag, True)
205209

206210
def get_enterprise_category(self, stream_id:EnterpriseStreamId) -> 'EnterpriseCategory':
207-
return self._get_category_or_tag(stream_id, self._tags, EnterpriseCategory)
211+
return self._get_category_or_tag(stream_id, self._tags, EnterpriseCategory, False)
208212

209213
def get_enterprise_tag(self, stream_id:EnterpriseStreamId) -> 'EnterpriseTag':
210-
return self._get_category_or_tag(stream_id, self._tags, EnterpriseTag)
214+
return self._get_category_or_tag(stream_id, self._tags, EnterpriseTag, False)
211215

212216

213217

feedly/session.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from pprint import pprint
12
import time
23
from pathlib import Path
34
from typing import Dict, Any, Union, List, Optional
@@ -14,6 +15,7 @@
1415

1516
from feedly.data import FeedlyUser
1617
from feedly.protocol import RateLimitedAPIError, BadRequestAPIError, UnauthorizedAPIError, ServerAPIError, APIClient, WrappedHTTPError
18+
from feedly.stream import StreamIdBase
1719

1820

1921
class Auth:
@@ -225,10 +227,5 @@ def do_api_request(self, relative_url:str, method:str=None, data:Dict=None,
225227

226228
sess = FeedlySession(auth)
227229

228-
sess.user.get_enterprise_tags()
229-
# sess.user.get_enterprise_categories()
230-
231-
# with FeedlySession(auth_token=token, user_id=uid) as sess:
232-
# opts = StreamOptions(max_count=30)
233-
# for i, eid in enumerate(sess.user.get_category('politics').stream_ids(opts)):
234-
# print(i, eid)
230+
for k, v in sess.user.get_categories().items():
231+
pprint(f"{k} -- {v['label']}")

feedly/stream.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def is_enterprise_stream(self):
3737
return self.source == STREAM_SOURCE_ENTERPRISE
3838

3939
@staticmethod
40-
def from_string(self, id_:str):
40+
def from_string(id_:str):
4141
parts = id_.split('/')
4242
if len(parts) < 4:
4343
raise ValueError(f'invalid id {id_}')
@@ -50,7 +50,7 @@ def from_string(self, id_:str):
5050
return StreamIdBase(id_, STREAM_SOURCE_UNKNOWN, 'unknown', 'unknown')
5151

5252
def __repr__(self):
53-
return f'StreamId: {self.id_}>'
53+
return f'<stream:{self.id}>'
5454

5555
def __str__(self):
5656
return self.__repr__()

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
EMAIL = 'kireet@feedly.com'
1919
AUTHOR = 'Kireet'
2020
REQUIRES_PYTHON = '>=3.6.0'
21-
VERSION = 0.14
21+
VERSION = 0.15
2222

2323
# What packages are required for this module to be executed?
2424
with open('requirements.txt') as f:

0 commit comments

Comments
 (0)