SubredditWidgets¶
-
class
praw.models.
SubredditWidgets
(subreddit)¶ Class to represent a subreddit’s widgets.
Create an instance like so:
widgets = reddit.subreddit('redditdev').widgets
Data will be lazy-loaded. By default, PRAW will not request progressively loading images from Reddit. To enable this, instantiate a SubredditWidgets object, then set the attribute
progressive_images
toTrue
before performing any action that would result in a network request.widgets = reddit.subreddit('redditdev').widgets widgets.progressive_images = True for widget in widgets.sidebar: # do something
Access a subreddit’s widgets with the following attributes:
print(widgets.id_card) print(widgets.moderators_widget) print(widgets.sidebar) print(widgets.topbar)
The attribute
id_card
contains the subreddit’s ID card, which displays information like the number of subscribers.The attribute
moderators_widget
contains the subreddit’s moderators widget, which lists the moderators of the subreddit.The attribute
sidebar
contains a list of widgets which make up the sidebar of the subreddit.The attribute
topbar
contains a list of widgets which make up the top bar of the subreddit.Currently available Widgets:
ButtonWidget
Calendar
CommunityList
CustomWidget
IDCard
ImageWidget
Menu
ModeratorsWidget
RulesWidget
TextArea
-
__init__
(subreddit)¶ Initialize the class.
Parameters: subreddit – The Subreddit
the widgets belong to.
-
items
¶ Get this subreddit’s widgets as a dict from ID to widget.
-
moderators_widget
¶ Get this subreddit’s
ModeratorsWidget
.
-
classmethod
parse
(data, reddit)¶ Return an instance of
cls
fromdata
.Parameters: - data – The structured data.
- reddit – An instance of
Reddit
.
-
refresh
()¶ Refresh the subreddit’s widgets.
By default, PRAW will not request progressively loading images from Reddit. To enable this, set the attribute
progressive_images
toTrue
prior to callingrefresh()
.widgets = reddit.subreddit('redditdev').widgets widgets.progressive_images = True widgets.refresh()
Get a list of Widgets that make up the sidebar.
-
topbar
¶ Get a list of Widgets that make up the top bar.