text stringlengths 81 112k |
|---|
Return the json dictionary containing rules for a subreddit.
:param subreddit: The subreddit whose rules we will return.
def get_rules(self, subreddit, bottom=False):
"""Return the json dictionary containing rules for a subreddit.
:param subreddit: The subreddit whose rules we will return.
... |
Return a Submission object for the sticky of the subreddit.
:param bottom: Get the top or bottom sticky. If the subreddit has only
a single sticky, it is considered the top one.
def get_sticky(self, subreddit, bottom=False):
"""Return a Submission object for the sticky of the subreddit.
... |
Return a Submission object for the given url or submission_id.
:param comment_limit: The desired number of comments to fetch. If <= 0
fetch the default number for the session's user. If None, fetch the
maximum possible.
:param comment_sort: The sort order for retrieved comments.... |
Generate Submission objects for each item provided in `fullnames`.
A submission fullname looks like `t3_<base36_id>`. Submissions are
yielded in the same order they appear in `fullnames`.
Up to 100 items are batched at a time -- this happens transparently.
The additional parameters ar... |
Return a Subreddit object for the subreddit_name specified.
The additional parameters are passed directly into the
:class:`.Subreddit` constructor.
def get_subreddit(self, subreddit_name, *args, **kwargs):
"""Return a Subreddit object for the subreddit_name specified.
The additional p... |
Return a list of recommended subreddits as Subreddit objects.
Subreddits with activity less than a certain threshold, will not have
any recommendations due to lack of data.
:param subreddits: A list of subreddits (either names or Subreddit
objects) to base the recommendations on.
... |
Return a get_content generator for top submissions.
Corresponds to the submissions provided by
``https://www.reddit.com/top/`` for the session.
The additional parameters are passed directly into
:meth:`.get_content`. Note: the `url` parameter cannot be altered.
def get_top(self, *args... |
Return a get_content generator for gilded submissions.
Corresponds to the submissions provided by
``https://www.reddit.com/gilded/`` for the session.
The additional parameters are passed directly into
:meth:`.get_content`. Note: the `url` parameter cannot be altered.
def get_gilded(se... |
Return the json dictionary containing traffic stats for a subreddit.
:param subreddit: The subreddit whose /about/traffic page we will
collect.
def get_traffic(self, subreddit):
"""Return the json dictionary containing traffic stats for a subreddit.
:param subreddit: The subreddit... |
Return a WikiPage object for the subreddit and page provided.
def get_wiki_page(self, subreddit, page):
"""Return a WikiPage object for the subreddit and page provided."""
return objects.WikiPage(self, six.text_type(subreddit), page.lower()) |
Return True if username is valid and available, otherwise False.
def is_username_available(self, username):
"""Return True if username is valid and available, otherwise False."""
params = {'user': username}
try:
result = self.request_json(self.config['username_available'],
... |
Return a generator for submissions that match the search query.
:param query: The query string to search for. If query is a URL only
submissions which link to that URL will be returned.
:param subreddit: Limit search results to the subreddit if provided.
:param sort: The sort order ... |
Return subreddits whose display name contains the query.
def search_reddit_names(self, query):
"""Return subreddits whose display name contains the query."""
data = {'query': query}
results = self.request_json(self.config['search_reddit_names'],
data=data)
... |
Accept a moderator invite to the given subreddit.
Callable upon an instance of Subreddit with no arguments.
:returns: The json response from the server.
def accept_moderator_invite(self, subreddit):
"""Accept a moderator invite to the given subreddit.
Callable upon an instance of Sub... |
Clear any existing authentication on the reddit object.
This function is implicitly called on `login` and
`set_access_credentials`.
def clear_authentication(self):
"""Clear any existing authentication on the reddit object.
This function is implicitly called on `login` and
`set... |
Delete the currently authenticated redditor.
WARNING!
This action is IRREVERSIBLE. Use only if you're okay with NEVER
accessing this reddit account again.
:param password: password for currently authenticated account
:param message: optional 'reason for deletion' message.
... |
Create or edit a wiki page with title `page` for `subreddit`.
:returns: The json response from the server.
def edit_wiki_page(self, subreddit, page, content, reason=''):
"""Create or edit a wiki page with title `page` for `subreddit`.
:returns: The json response from the server.
"""
... |
Return the access information for an OAuth2 authorization grant.
:param code: the code received in the request from the OAuth2 server
:param update_session: Update the current session with the retrieved
token(s).
:returns: A dictionary with the key/value pairs for access_token,
... |
Return available flair choices and current flair.
:param link: If link is given, return the flair options for this
submission. Not normally given directly, but instead set by calling
the flair_choices method for Submission objects.
Use the default for the session's user.
... |
Return a UserList of Redditors with whom the user is friends.
def get_friends(self, **params):
"""Return a UserList of Redditors with whom the user is friends."""
url = self.config['friends']
return self.request_json(url, params=params)[0] |
Return a LoggedInRedditor object.
Note: This function is only intended to be used with an 'identity'
providing OAuth2 grant.
def get_me(self):
"""Return a LoggedInRedditor object.
Note: This function is only intended to be used with an 'identity'
providing OAuth2 grant.
... |
Return True if OAuth2 authorized for the passed in scope(s).
def has_scope(self, scope):
"""Return True if OAuth2 authorized for the passed in scope(s)."""
if not self.is_oauth_session():
return False
if '*' in self._authentication:
return True
if isinstance(scop... |
Login to a reddit site.
**DEPRECATED**. Will be removed in a future version of PRAW.
https://www.reddit.com/comments/2ujhkr/
https://www.reddit.com/comments/37e2mv/
Look for username first in parameter, then praw.ini and finally if both
were empty get it from stdin. Look for p... |
Return updated access information for an OAuth2 authorization grant.
:param refresh_token: The refresh token used to obtain the updated
information. When not provided, use the stored refresh_token.
:param update_session: Update the session with the returned data.
:returns: A diction... |
Select user flair or link flair on subreddits.
This can only be used for assigning your own name flair or link flair
on your own submissions. For assigning other's flairs using moderator
access, see :meth:`~praw.__init__.ModFlairMixin.set_flair`.
:param item: A string, Subreddit object... |
Set the credentials used for OAuth2 authentication.
Calling this function will overwrite any currently existing access
credentials.
:param scope: A set of reddit scopes the tokens provide access to
:param access_token: the access token of the authentication
:param refresh_token... |
Create a new subreddit.
:returns: The json response from the server.
This function may result in a captcha challenge. PRAW will
automatically prompt you for a response. See :ref:`handling-captchas`
if you want to manually handle captchas.
def create_subreddit(self, name, title, descri... |
Delete an image from the subreddit.
:param name: The name of the image if removing a CSS image.
:param header: When true, delete the subreddit header.
:returns: The json response from the server.
def delete_image(self, subreddit, name=None, header=False):
"""Delete an image from the su... |
Set the settings for the given subreddit.
:param subreddit: Must be a subreddit object.
:returns: The json response from the server.
def set_settings(self, subreddit, title, public_description='',
description='', language='en', subreddit_type='public',
content... |
Set stylesheet for the given subreddit.
:returns: The json response from the server.
def set_stylesheet(self, subreddit, stylesheet):
"""Set stylesheet for the given subreddit.
:returns: The json response from the server.
"""
subreddit = six.text_type(subreddit)
data ... |
Upload an image to the subreddit.
:param image_path: A path to the jpg or png image you want to upload.
:param name: The name to provide the image. When None the name will be
filename less any extension.
:param header: When True, upload the image as the subreddit header.
:pa... |
Update only the given settings for the given subreddit.
The settings to update must be given by keyword and match one of the
parameter names in `set_settings`.
:returns: The json response from the server.
def update_settings(self, subreddit, **kwargs):
"""Update only the given setting... |
Add a flair template to the given subreddit.
:returns: The json response from the server.
def add_flair_template(self, subreddit, text='', css_class='',
text_editable=False, is_link=False):
"""Add a flair template to the given subreddit.
:returns: The json response ... |
Clear flair templates for the given subreddit.
:returns: The json response from the server.
def clear_flair_templates(self, subreddit, is_link=False):
"""Clear flair templates for the given subreddit.
:returns: The json response from the server.
"""
data = {'r': six.text_type... |
Configure the flair setting for the given subreddit.
:returns: The json response from the server.
def configure_flair(self, subreddit, flair_enabled=False,
flair_position='right',
flair_self_assign=False,
link_flair_enabled=False,
... |
Delete the flair for the given user on the given subreddit.
:returns: The json response from the server.
def delete_flair(self, subreddit, user):
"""Delete the flair for the given user on the given subreddit.
:returns: The json response from the server.
"""
data = {'r': six.t... |
Return a get_content generator of flair mappings.
:param subreddit: Either a Subreddit object or the name of the
subreddit to return the flair list for.
The additional parameters are passed directly into
:meth:`.get_content`. Note: the `url`, `root_field`, `thing_field`, and
... |
Set flair for the user in the given subreddit.
`item` can be a string, Redditor object, or Submission object.
If `item` is a string it will be treated as the name of a Redditor.
This method can only be called by a subreddit moderator with flair
permissions. To set flair on yourself or ... |
Set flair for a group of users in the given subreddit.
flair_mapping should be a list of dictionaries with the following keys:
`user`: the user name,
`flair_text`: the flair text for the user (optional),
`flair_css_class`: the flair css class for the user (optional)
:retu... |
Return a get_content generator for moderation log items.
:param subreddit: Either a Subreddit object or the name of the
subreddit to return the modlog for.
:param mod: If given, only return the actions made by this moderator.
Both a moderator name or Redditor object can be used ... |
Return a get_content generator of banned users for the subreddit.
:param subreddit: The subreddit to get the banned user list for.
:param user_only: When False, the generator yields a dictionary of data
associated with the server response for that user. In such cases,
the Reddit... |
Return a get_content generator of contributors for the given subreddit.
If it's a public subreddit, then authentication as a
moderator of the subreddit is required. For protected/private
subreddits only access is required. See issue #246.
def get_contributors(self, subreddit, *args, **kwargs):... |
Return a get_content generator of edited items.
:param subreddit: Either a Subreddit object or the name of the
subreddit to return the edited items for. Defaults to `mod` which
includes items for all the subreddits you moderate.
The additional parameters are passed directly int... |
Return the stylesheet and images for the given subreddit.
def get_stylesheet(self, subreddit, **params):
"""Return the stylesheet and images for the given subreddit."""
url = self.config['stylesheet'].format(
subreddit=six.text_type(subreddit))
return self.request_json(url, params=p... |
Abdicate moderator status in a subreddit. Use with care.
:param subreddit: The name of the subreddit to leave `status` from.
:returns: the json response from the server.
def leave_moderator(self, subreddit):
"""Abdicate moderator status in a subreddit. Use with care.
:param subreddit... |
Abdicate status in a subreddit.
:param subreddit: The name of the subreddit to leave `status` from.
:param statusurl: The API URL which will be used in the leave request.
Please use :meth:`leave_contributor` or :meth:`leave_moderator`
rather than setting this directly.
... |
Copy a multireddit.
:param from_redditor: The username or Redditor object for the user
who owns the original multireddit
:param from_name: The name of the multireddit, belonging to
from_redditor
:param to_name: The name to copy the multireddit as. If None, uses
... |
Create a new multireddit.
:param name: The name of the new multireddit.
:param description_md: Optional description for the multireddit,
formatted in markdown.
:param icon_name: Optional, choose an icon name from this list: ``art
and design``, ``ask``, ``books``, ``busin... |
Delete a Multireddit.
Any additional parameters are passed directly into
:meth:`~praw.__init__.BaseReddit.request`
def delete_multireddit(self, name, *args, **kwargs):
"""Delete a Multireddit.
Any additional parameters are passed directly into
:meth:`~praw.__init__.BaseReddit.... |
Edit a multireddit, or create one if it doesn't already exist.
See :meth:`create_multireddit` for accepted parameters.
def edit_multireddit(self, *args, **kwargs):
"""Edit a multireddit, or create one if it doesn't already exist.
See :meth:`create_multireddit` for accepted parameters.
... |
Return a Multireddit object for the author and name specified.
:param redditor: The username or Redditor object of the user
who owns the multireddit.
:param multi: The name of the multireddit to fetch.
The additional parameters are passed directly into the
:class:`.Multired... |
Return a list of multireddits belonging to a redditor.
:param redditor: The username or Redditor object to find multireddits
from.
:returns: The json response from the server
The additional parameters are passed directly into
:meth:`~praw.__init__.BaseReddit.request_json`
... |
Rename a Multireddit.
:param current_name: The name of the multireddit to rename
:param new_name: The new name to assign to this multireddit
The additional parameters are passed directly into
:meth:`~praw.__init__.BaseReddit.request_json`
def rename_multireddit(self, current_name, new... |
Return a get_content generator of subreddits.
The Subreddits generated are those where the session's user is a
contributor.
The additional parameters are passed directly into
:meth:`.get_content`. Note: the `url` parameter cannot be altered.
def get_my_contributions(self, *args, **kwa... |
Return a get_content generator of subreddits.
The Subreddits generated are those where the session's user is a
moderator.
The additional parameters are passed directly into
:meth:`.get_content`. Note: the `url` parameter cannot be altered.
def get_my_moderation(self, *args, **kwargs):... |
Return a get_content generator of subreddits.
The subreddits generated are those that hat the session's user is
subscribed to.
The additional parameters are passed directly into
:meth:`.get_content`. Note: the `url` parameter cannot be altered.
def get_my_subreddits(self, *args, **kwa... |
Mark each of the supplied thing_ids as (un)read.
:returns: The json response from the server.
def _mark_as_read(self, thing_ids, unread=False):
"""Mark each of the supplied thing_ids as (un)read.
:returns: The json response from the server.
"""
data = {'id': ','.join(thing_id... |
Return a get_content generator for inboxed comment replies.
The additional parameters are passed directly into
:meth:`.get_content`. Note: the `url` parameter cannot be altered.
def get_comment_replies(self, *args, **kwargs):
"""Return a get_content generator for inboxed comment replies.
... |
Return a get_content generator for inbox (messages and comments).
The additional parameters are passed directly into
:meth:`.get_content`. Note: the `url` parameter cannot be altered.
def get_inbox(self, *args, **kwargs):
"""Return a get_content generator for inbox (messages and comments).
... |
Return a Message object corresponding to the given ID.
:param message_id: The ID or Fullname for a Message
The additional parameters are passed directly into
:meth:`~praw.objects.Message.from_id` of Message, and subsequently into
:meth:`.request_json`.
def get_message(self, message_id... |
Return a get_content generator for inbox (messages only).
The additional parameters are passed directly into
:meth:`.get_content`. Note: the `url` parameter cannot be altered.
def get_messages(self, *args, **kwargs):
"""Return a get_content generator for inbox (messages only).
The add... |
Return a get_content generator for inboxed submission replies.
The additional parameters are passed directly into
:meth:`.get_content`. Note: the `url` parameter cannot be altered.
def get_post_replies(self, *args, **kwargs):
"""Return a get_content generator for inboxed submission replies.
... |
Return a get_content generator for sent messages.
The additional parameters are passed directly into
:meth:`.get_content`. Note: the `url` parameter cannot be altered.
def get_sent(self, *args, **kwargs):
"""Return a get_content generator for sent messages.
The additional parameters a... |
Return a get_content generator for unread messages.
:param unset_has_mail: When True, clear the has_mail flag (orangered)
for the user.
:param update_user: If both `unset_has_mail` and `update user` is True,
set the `has_mail` attribute of the logged-in user to False.
T... |
Return a get_content generator for username mentions.
The additional parameters are passed directly into
:meth:`.get_content`. Note: the `url` parameter cannot be altered.
def get_mentions(self, *args, **kwargs):
"""Return a get_content generator for username mentions.
The additional ... |
Send a message to a redditor or a subreddit's moderators (mod mail).
:param recipient: A Redditor or Subreddit instance to send a message
to. A string can also be used in which case the string is treated
as a redditor unless it is prefixed with either '/r/' or '#', in
which ... |
Hide one or multiple objects in the context of the logged in user.
:param thing_id: A single fullname or list of fullnames,
representing objects which will be hidden.
:param _unhide: If True, unhide the object(s) instead. Use
:meth:`~praw.__init__.ReportMixin.unhide` rather than... |
Comment on the given thing with the given text.
:returns: A Comment object for the newly created comment.
def _add_comment(self, thing_id, text):
"""Comment on the given thing with the given text.
:returns: A Comment object for the newly created comment.
"""
def add_comment_h... |
Submit a new link to the given subreddit.
Accepts either a Subreddit object or a str containing the subreddit's
display name.
:param resubmit: If True, submit the link even if it has already been
submitted.
:param save: If True the new Submission will be saved after creatio... |
Subscribe to the given subreddit.
:param subreddit: Either the subreddit name or a subreddit object.
:param unsubscribe: When True, unsubscribe.
:returns: The json response from the server.
def subscribe(self, subreddit, unsubscribe=False):
"""Subscribe to the given subreddit.
... |
Some custom patches on top of the python webbrowser module to fix
user reported bugs and limitations of the module.
def patch_webbrowser():
"""
Some custom patches on top of the python webbrowser module to fix
user reported bugs and limitations of the module.
"""
# https://bugs.python.org/issu... |
Setup terminal and initialize curses. Most of this copied from
curses.wrapper in order to convert the wrapper into a context manager.
def curses_session():
"""
Setup terminal and initialize curses. Most of this copied from
curses.wrapper in order to convert the wrapper into a context manager.
"""
... |
Move the cursor up or down by the given increment.
Params:
direction (int): `1` will move the cursor down one item and `-1`
will move the cursor up one item.
n_windows (int): The number of items that are currently being drawn
on the screen.
Retur... |
Move the page down (positive direction) or up (negative direction).
Paging down:
The post on the bottom of the page becomes the post at the top of
the page and the cursor is moved to the top.
Paging up:
The post at the top of the page becomes the post at the bottom o... |
Flip the orientation of the page.
def flip(self, n_windows):
"""
Flip the orientation of the page.
"""
assert n_windows >= 0
self.page_index += (self.step * n_windows)
self.cursor_index = n_windows
self.inverted = not self.inverted
self.top_item_height =... |
Parse a key represented by a string and return its character code.
def parse(cls, key):
"""
Parse a key represented by a string and return its character code.
"""
try:
if isinstance(key, int):
return key
elif re.match('[<]KEY_.*[>]', key):
... |
Guess based on the file extension.
Args:
url (text): Web url that was linked to by a reddit submission.
Returns:
modified_url (text): The url (or filename) that will be used when
constructing the command to run.
content_type (text): The mime-type tha... |
Re-download all submissions and reset the page index
def refresh_content(self, order=None, name=None):
"""
Re-download all submissions and reset the page index
"""
order = order or self.content.order
# Preserve the query if staying on the current page
if name is None:
... |
Open a prompt to search the given subreddit
def search_subreddit(self, name=None):
"""
Open a prompt to search the given subreddit
"""
name = name or self.content.name
query = self.term.prompt_input('Search {0}: '.format(name))
if not query:
return
... |
If on a subreddit, remember it and head back to the front page.
If this was pressed on the front page, go back to the last subreddit.
def show_frontpage(self):
"""
If on a subreddit, remember it and head back to the front page.
If this was pressed on the front page, go back to the last ... |
Select the current submission to view posts.
def open_submission(self, url=None):
"""
Select the current submission to view posts.
"""
if url is None:
data = self.get_selected_item()
url = data['permalink']
if data.get('url_type') == 'selfpost':
... |
Open a link with the webbrowser
def open_link(self):
"""
Open a link with the webbrowser
"""
data = self.get_selected_item()
if data['url_type'] == 'selfpost':
self.open_submission()
elif data['url_type'] == 'x-post subreddit':
self.refresh_conte... |
Post a new submission to the given subreddit.
def post_submission(self):
"""
Post a new submission to the given subreddit.
"""
# Check that the subreddit can be submitted to
name = self.content.name
if '+' in name or name in ('/r/all', '/r/front', '/r/me', '/u/saved'):
... |
Re-download comments and reset the page index
def refresh_content(self, order=None, name=None):
"""
Re-download comments and reset the page index
"""
order = order or self.content.order
url = name or self.content.name
# Hack to allow an order specified in the name by pr... |
Toggle the selected comment tree between visible and hidden
def toggle_comment(self):
"""
Toggle the selected comment tree between visible and hidden
"""
current_index = self.nav.absolute_index
self.content.toggle(current_index)
# This logic handles a display edge case ... |
Open the link contained in the selected item.
If there is more than one link contained in the item, prompt the user
to choose which link to open.
def open_link(self):
"""
Open the link contained in the selected item.
If there is more than one link contained in the item, prompt... |
Open the selected item with the system's pager
def open_pager(self):
"""
Open the selected item with the system's pager
"""
n_rows, n_cols = self.term.stdscr.getmaxyx()
if self.config['max_pager_cols'] is not None:
n_cols = min(n_cols, self.config['max_pager_cols'])... |
Open the selected comment with the URL viewer
def comment_urlview(self):
"""
Open the selected comment with the URL viewer
"""
data = self.get_selected_item()
comment = data.get('body') or data.get('text') or data.get('url_full')
if comment:
self.term.open_ur... |
Move the cursor up to the comment's parent. If the comment is
top-level, jump to the previous top-level comment.
def move_parent_up(self):
"""
Move the cursor up to the comment's parent. If the comment is
top-level, jump to the previous top-level comment.
"""
cursor = se... |
Jump to the next comment that's at the same level as the selected
comment and shares the same parent.
def move_sibling_next(self):
"""
Jump to the next comment that's at the same level as the selected
comment and shares the same parent.
"""
cursor = self.nav.absolute_ind... |
Return function to generate Redditor listings.
def _get_redditor_listing(subpath=''):
"""Return function to generate Redditor listings."""
def _listing(self, sort='new', time='all', *args, **kwargs):
"""Return a get_content generator for some RedditContentObject type.
:param sort: Specify the ... |
Return function to generate specific subreddit Submission listings.
def _get_sorter(subpath='', **defaults):
"""Return function to generate specific subreddit Submission listings."""
@restrict_access(scope='read')
def _sorted(self, *args, **kwargs):
"""Return a get_content generator for some Reddit... |
Return a function for relationship modification.
Used to support friending (user-to-user), as well as moderating,
contributor creating, and banning (user-to-subreddit).
def _modify_relationship(relationship, unlink=False, is_sub=False):
"""Return a function for relationship modification.
Used to supp... |
Return a requests Request object that can be "prepared".
def _prepare_request(reddit_session, url, params, data, auth, files,
method=None):
"""Return a requests Request object that can be "prepared"."""
# Requests using OAuth for authorization must switch to using the oauth
# domain.
... |
Return the new url or None if there are no redirects.
Raise exceptions if appropriate.
def _raise_redirect_exceptions(response):
"""Return the new url or None if there are no redirects.
Raise exceptions if appropriate.
"""
if response.status_code not in [301, 302, 307]:
return None
n... |
Raise specific errors on some status codes.
def _raise_response_exceptions(response):
"""Raise specific errors on some status codes."""
if not response.ok and 'www-authenticate' in response.headers:
msg = response.headers['www-authenticate']
if 'insufficient_scope' in msg:
raise OAu... |
Return an argument converted to a reddit-formatted list.
The returned format is a comma deliminated list. Each element is a string
representation of an object. Either given as a string or as an object that
is then converted to its string representation.
def _to_reddit_list(arg):
"""Return an argument ... |
Prompt user for captcha solution and return a prepared result.
def _get_captcha(reddit_session, captcha_id):
"""Prompt user for captcha solution and return a prepared result."""
url = urljoin(reddit_session.config['captcha'],
captcha_id + '.png')
sys.stdout.write('Captcha URL: {0}\nCaptch... |
Return a decorator that enforces API request limit guidelines.
We are allowed to make a API request every api_request_delay seconds as
specified in praw.ini. This value may differ from reddit to reddit. For
reddit.com it is 2. Any function decorated with this will be forced to
delay _ra... |
Responsible for dispatching the request and returning the result.
Network level exceptions should be raised and only
``requests.Response`` should be returned.
:param request: A ``requests.PreparedRequest`` object containing all
the data necessary to perform the request.
:pa... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.