Skip to content

Commit 48949aa

Browse files
committed
optimized InoreaderClient.fetch_articles
1 parent 6efc1c0 commit 48949aa

File tree

1 file changed

+10
-14
lines changed

1 file changed

+10
-14
lines changed

inoreader/client.py

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -161,23 +161,24 @@ def __get_stream_contents(
161161
else:
162162
return response["items"], None
163163

164-
def fetch_articles(self, folder=None, tags=None, unread=True, starred=False, limit=None, n=50):
164+
def fetch_articles(
165+
self, stream_id=None, folder=None, tags=None, unread=True, starred=False, limit=None, n=50
166+
):
165167
self.check_token()
166168

167-
url = urljoin(BASE_URL, self.STREAM_CONTENTS_PATH)
168-
if folder:
169-
url = urljoin(url, quote_plus(self.GENERAL_TAG_TEMPLATE.format(folder)))
169+
if not stream_id and folder:
170+
stream_id = self.GENERAL_TAG_TEMPLATE.format(folder)
170171

171-
params = {"n": n, "c": str(uuid4())}
172+
params = {"stream_id": stream_id, "n": n, "c": str(uuid4())}
172173
if unread:
173174
params["xt"] = self.READ_TAG
174175

175176
if starred:
176177
params["it"] = self.STARRED_TAG
177178

178179
fetched_count = 0
179-
response = self.parse_response(self.session.post(url, params=params, proxies=self.proxies))
180-
for data in response["items"]:
180+
items, continuation = self.__get_stream_contents(**params)
181+
for data in items:
181182
categories = {
182183
category.split("/")[-1]
183184
for category in data.get("categories", [])
@@ -191,13 +192,10 @@ def fetch_articles(self, folder=None, tags=None, unread=True, starred=False, lim
191192
if limit and fetched_count >= limit:
192193
break
193194

194-
continuation = response.get("continuation")
195195
while continuation and (not limit or fetched_count < limit):
196196
params["c"] = continuation
197-
response = self.parse_response(
198-
self.session.post(url, params=params, proxies=self.proxies)
199-
)
200-
for data in response["items"]:
197+
items, continuation = self.__get_stream_contents(**params)
198+
for data in items:
201199
categories = {
202200
category.split("/")[-1]
203201
for category in data.get("categories", [])
@@ -210,8 +208,6 @@ def fetch_articles(self, folder=None, tags=None, unread=True, starred=False, lim
210208
if limit and fetched_count >= limit:
211209
break
212210

213-
continuation = response.get("continuation")
214-
215211
def fetch_unread(self, folder=None, tags=None, limit=None):
216212
for article in self.fetch_articles(folder=folder, tags=tags, unread=True):
217213
yield article

0 commit comments

Comments
 (0)