@@ -216,6 +216,51 @@ def fetch_articles(self, folder=None, tags=None, unread=True, starred=False, lim
216216 break
217217
218218 continuation = response .get ('continuation' )
219+
220+ def fetch_articles_by_tag (self , tag :str , limit = None ):
221+ self .check_token ()
222+
223+ url = urljoin (BASE_URL , self .STREAM_CONTENTS_PATH )
224+
225+ params = {'c' : str (uuid4 ())}
226+ params ['it' ] = tag
227+
228+ fetched_count = 0
229+ response = self .parse_response (self .session .post (url , params = params , proxies = self .proxies ))
230+ for data in response ['items' ]:
231+ categories = set (
232+ [
233+ category .split ('/' )[- 1 ]
234+ for category in data .get ('categories' , [])
235+ if category .find ('label' ) > 0
236+ ]
237+ )
238+
239+ yield Article .from_json (data )
240+ fetched_count += 1
241+ if limit and fetched_count >= limit :
242+ break
243+
244+ continuation = response .get ('continuation' )
245+ while continuation and (not limit or fetched_count < limit ):
246+ params ['c' ] = continuation
247+ response = self .parse_response (
248+ self .session .post (url , params = params , proxies = self .proxies )
249+ )
250+ for data in response ['items' ]:
251+ categories = set (
252+ [
253+ category .split ('/' )[- 1 ]
254+ for category in data .get ('categories' , [])
255+ if category .find ('label' ) > 0
256+ ]
257+ )
258+ yield Article .from_json (data )
259+ fetched_count += 1
260+ if limit and fetched_count >= limit :
261+ break
262+
263+ continuation = response .get ('continuation' )
219264
220265 def fetch_unread (self , folder = None , tags = None , limit = None ):
221266 for article in self .fetch_articles (folder = folder , tags = tags , unread = True ):
0 commit comments