ListingGenerator¶
ListingGenerator
is a utility class that fetches items from the listing endpoint, parses the response, and yields items as they are found.
If the item kind cannot be identified, aPRAWBase
is returned which automatically assigns itself all the data attributes found.
-
class
apraw.models.
ListingGenerator
(reddit: Reddit, endpoint: str, max_wait: int = 16, kind_filter: List[str] = [], subreddit=None)¶ The model to request, parse and poll listings from Reddit.
- reddit: Reddit
- The
Reddit
instance with which requests are made. - endpoint: str
- The endpoint to make requests on.
- max_wait: int
- The maximum amount of seconds to wait before re-requesting in streams.
- kind_filter:
- Kinds to return if given, otherwise all are returned.
- subreddit: Subreddit
- The subreddit to inject as a dependency into items if given.
Note
ListingGenerator will automatically make requests until none more are found or the limit has been reached.
-
get
(limit: int = 25, **kwargs) → AsyncIterator[apraw.models.helpers.apraw_base.aPRAWBase]¶ Yields items found in the listing.
Parameters: - limit (int) – The maximum amount of items to search. If
None
, all are returned. - kwargs (**Dict) – Query parameters to append to the request URL.
Yields: - subreddit (Subreddit) – The subreddit found in the listing.
- comment (Comment) – The comment found in the listing.
- submission (Submission) – The submission found in the listing.
- mod_action (ModAction) – The mod action found in the listing.
- wikipage_revision (WikipageRevision) – The wikipage revision found in the listing.
- item (aPRAWBase) – A model of the item’s data if kind couldn’t be identified.
- limit (int) – The maximum amount of items to search. If
-
stream
(skip_existing: bool = False, **kwargs) → AsyncIterator[apraw.models.helpers.apraw_base.aPRAWBase]¶ Stream items from an endpoint.
Streams use the
asyncio.sleep()
call to wait in between requests. If no items are found, the wait time is double untilmax_wait
has been reached, at which point it’s reset to 1.Parameters: - skip_existing (bool) – Whether to skip items made before the call.
- kwargs (**Dict) – Query parameters to append to the request URL.
Yields: - subreddit (Subreddit) – The subreddit found in the listing.
- comment (Comment) – The comment found in the listing.
- submission (Submission) – The submission found in the listing.
- mod_action (ModAction) – The mod action found in the listing.
- wikipage_revision (WikipageRevision) – The wikipage revision found in the listing.
- item (aPRAWBase) – A model of the item’s data if kind couldn’t be identified.