SubredditRedditorFlairTemplates¶
- class praw.models.reddit.subreddit.SubredditRedditorFlairTemplates(subreddit)¶
Provide functions to interact with
Redditorflair templates.- Parameters:
subreddit (models.Subreddit)
- __init__(subreddit)¶
Initialize a
SubredditFlairTemplatesinstance.- Parameters:
subreddit (
Subreddit) – The subreddit whose flair templates to work with.- Return type:
None
Note
This class should not be initialized directly. Instead, obtain an instance via:
reddit.subreddit("test").flair.templatesorreddit.subreddit("test").flair.link_templates.
- __iter__()¶
Iterate through the user flair templates.
For example:
for template in reddit.subreddit("test").flair.templates: print(template)
- add(text, *, allowable_content=None, background_color=None, css_class='', max_emojis=None, mod_only=None, text_color=None, text_editable=False)¶
Add a redditor flair template to the associated subreddit.
- Parameters:
text (
str) – The flair template’s text.allowable_content (
str|None) – If specified, most be one of"all","emoji", or"text"to restrict content to that type. If set to"emoji"then the"text"param must be a valid emoji string, for example,":snoo:".background_color (
str|None) – The flair template’s new background color, as a hex color.css_class (
str) – The flair template’s css_class (default:"").max_emojis (
int|None) – Maximum emojis in the flair (Reddit defaults this value to10).mod_only (
bool|None) – Indicate if the flair can only be used by moderators.text_color (
str|None) – The flair template’s new text color, either"light"or"dark".text_editable (
bool) – Indicate if the flair text can be modified for each redditor that sets it (default:False).
- Return type:
For example, to add an editable redditor flair try:
reddit.subreddit("test").flair.templates.add( "PRAW", css_class="praw", text_editable=True, )
- clear()¶
Remove all
Redditorflair templates from the subreddit.For example:
reddit.subreddit("test").flair.templates.clear()
- Return type:
- delete(template_id)¶
Remove a flair template provided by
template_id.For example, to delete the first
Redditorflair template listed, try:template_info = list(subreddit.flair.templates)[0] subreddit.flair.templates.delete(template_info["id"])
- static flair_type(*, is_link)¶
Return
"LINK_FLAIR"or"USER_FLAIR"depending onis_linkvalue.
- reorder(flair_list)¶
Reorder a list of flairs.
For example, to reverse the order of the
Redditorflair templates list try:subreddit = reddit.subreddit("test") flairs = [flair["id"] for flair in subreddit.flair.templates] subreddit.flair.templates.reorder(list(reversed(flairs)))
- update(template_id, *, allowable_content=None, background_color=None, css_class=None, fetch=True, max_emojis=None, mod_only=None, text=None, text_color=None, text_editable=None)¶
Update the flair template provided by
template_id.- Parameters:
template_id (
str) – The flair template to update. If not valid then an exception will be thrown.allowable_content (
str|None) – If specified, most be one of"all","emoji", or"text"to restrict content to that type. If set to"emoji"then the"text"param must be a valid emoji string, for example,":snoo:".background_color (
str|None) – The flair template’s new background color, as a hex color.css_class (
str|None) – The flair template’s new css_class (default:"").fetch (
bool) – Whether PRAW will fetch existing information on the existing flair before updating (default:True).max_emojis (
int|None) – Maximum emojis in the flair (Reddit defaults this value to10).mod_only (
bool|None) – Indicate if the flair can only be used by moderators.text_color (
str|None) – The flair template’s new text color, either"light"or"dark".text_editable (
bool|None) – Indicate if the flair text can be modified for each redditor that sets it (default:False).
- Return type:
Warning
If parameter
fetchis set toFalse, all parameters not provided will be reset to their default (NoneorFalse) values.For example, to make a user flair template text editable, try:
template_info = list(subreddit.flair.templates)[0] subreddit.flair.templates.update( template_info["id"], text=template_info["flair_text"], text_editable=True, )