Skip to content

Commit 1cf4668

Browse files
committed
add parameter limit to InoreaderClient.fetch_articles
1 parent f08edb4 commit 1cf4668

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

inoreader/client.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ def __get_stream_contents(self, stream_id, continuation=''):
163163
else:
164164
return response['items'], None
165165

166-
def fetch_articles(self, folder=None, tags=None, unread=True, starred=False):
166+
def fetch_articles(self, folder=None, tags=None, unread=True, starred=False, limit=None):
167167
self.check_token()
168168

169169
url = urljoin(BASE_URL, self.STREAM_CONTENTS_PATH)
@@ -180,6 +180,7 @@ def fetch_articles(self, folder=None, tags=None, unread=True, starred=False):
180180
if starred:
181181
params['it'] = self.STARRED_TAG
182182

183+
fetched_count = 0
183184
response = self.parse_response(self.session.post(url, params=params, proxies=self.proxies))
184185
for data in response['items']:
185186
categories = set([
@@ -190,8 +191,11 @@ def fetch_articles(self, folder=None, tags=None, unread=True, starred=False):
190191
continue
191192

192193
yield Article.from_json(data)
194+
fetched_count += 1
195+
if limit and fetched_count >= limit:
196+
break
193197

194-
continuation = response.get('continuation')
198+
continuation = response.get('continuation') and (not limit or fetched_count < limit)
195199
while continuation:
196200
params['c'] = continuation
197201
response = self.parse_response(
@@ -205,14 +209,17 @@ def fetch_articles(self, folder=None, tags=None, unread=True, starred=False):
205209
if tags and not categories.issuperset(set(tags)):
206210
continue
207211
yield Article.from_json(data)
212+
fetched_count += 1
213+
if limit and fetched_count >= limit:
214+
break
208215

209-
continuation = response.get('continuation')
216+
continuation = response.get('continuation') and (not limit or fetched_count < limit)
210217

211-
def fetch_unread(self, folder=None, tags=None):
218+
def fetch_unread(self, folder=None, tags=None, limit=None):
212219
for article in self.fetch_articles(folder=folder, tags=tags, unread=True):
213220
yield article
214221

215-
def fetch_starred(self, folder=None, tags=None):
222+
def fetch_starred(self, folder=None, tags=None, limit=None):
216223
for article in self.fetch_articles(folder=folder, tags=tags, unread=False, starred=True):
217224
yield article
218225

0 commit comments

Comments
 (0)