INSTRUCTION stringlengths 1 8.43k | RESPONSE stringlengths 75 104k |
|---|---|
View the context surrounding the selected comment. | def view_context(self):
"""
View the context surrounding the selected comment.
"""
url = self.get_selected_item().get('context')
if url:
self.selected_page = self.open_submission_page(url) |
Open the full submission and comment tree for the selected comment. | def open_submission(self):
"""
Open the full submission and comment tree for the selected comment.
"""
url = self.get_selected_item().get('submission_permalink')
if url:
self.selected_page = self.open_submission_page(url) |
Decorator for Page methods that require the user to be authenticated. | def logged_in(f):
"""
Decorator for Page methods that require the user to be authenticated.
"""
@wraps(f)
def wrapped_method(self, *args, **kwargs):
if not self.reddit.is_oauth_session():
self.term.show_notification('Not logged in')
return None
return f(self,... |
Main control loop runs the following steps: 1. Re - draw the screen 2. Wait for user to press a key ( includes terminal resizing ) 3. Trigger the method registered to the input key 4. Check if there are any nested pages that need to be looped over | def loop(self):
"""
Main control loop runs the following steps:
1. Re-draw the screen
2. Wait for user to press a key (includes terminal resizing)
3. Trigger the method registered to the input key
4. Check if there are any nested pages that need to be loop... |
Cycle to preview the previous theme from the internal list of themes. | def previous_theme(self):
"""
Cycle to preview the previous theme from the internal list of themes.
"""
theme = self.term.theme_list.previous(self.term.theme)
while not self.term.check_theme(theme):
theme = self.term.theme_list.previous(theme)
self.term.set_t... |
Cycle to preview the next theme from the internal list of themes. | def next_theme(self):
"""
Cycle to preview the next theme from the internal list of themes.
"""
theme = self.term.theme_list.next(self.term.theme)
while not self.term.check_theme(theme):
theme = self.term.theme_list.next(theme)
self.term.set_theme(theme)
... |
Move the cursor to the first item on the page. | def move_page_top(self):
"""
Move the cursor to the first item on the page.
"""
self.nav.page_index = self.content.range[0]
self.nav.cursor_index = 0
self.nav.inverted = False |
Move the cursor to the last item on the page. | def move_page_bottom(self):
"""
Move the cursor to the last item on the page.
"""
self.nav.page_index = self.content.range[1]
self.nav.cursor_index = 0
self.nav.inverted = True |
Upvote the currently selected item. | def upvote(self):
"""
Upvote the currently selected item.
"""
data = self.get_selected_item()
if 'likes' not in data:
self.term.flash()
elif getattr(data['object'], 'archived'):
self.term.show_notification("Voting disabled for archived post", style... |
Downvote the currently selected item. | def downvote(self):
"""
Downvote the currently selected item.
"""
data = self.get_selected_item()
if 'likes' not in data:
self.term.flash()
elif getattr(data['object'], 'archived'):
self.term.show_notification("Voting disabled for archived post", s... |
Mark the currently selected item as saved through the reddit API. | def save(self):
"""
Mark the currently selected item as saved through the reddit API.
"""
data = self.get_selected_item()
if 'saved' not in data:
self.term.flash()
elif not data['saved']:
with self.term.loader('Saving'):
data['objec... |
Prompt to log into the user s account or log out of the current account. | def login(self):
"""
Prompt to log into the user's account, or log out of the current
account.
"""
if self.reddit.is_oauth_session():
ch = self.term.show_notification('Log out? (y/n)')
if ch in (ord('y'), ord('Y')):
self.oauth.clear_oauth_d... |
Reply to the selected item. This is a utility method and should not be bound to a key directly. | def reply(self):
"""
Reply to the selected item. This is a utility method and should not
be bound to a key directly.
Item type:
Submission - add a top level comment
Comment - add a comment reply
Message - reply to a private message
"""
... |
Delete a submission or comment. | def delete_item(self):
"""
Delete a submission or comment.
"""
data = self.get_selected_item()
if data.get('author') != self.reddit.user.name:
self.term.flash()
return
prompt = 'Are you sure you want to delete this? (y/n): '
if not self.te... |
Edit a submission or comment. | def edit(self):
"""
Edit a submission or comment.
"""
data = self.get_selected_item()
if data.get('author') != self.reddit.user.name:
self.term.flash()
return
if data['type'] == 'Submission':
content = data['text']
info = d... |
Send a new private message to another user. | def send_private_message(self):
"""
Send a new private message to another user.
"""
message_info = docs.MESSAGE_FILE
with self.term.open_editor(message_info) as text:
if not text:
self.term.show_notification('Canceled')
return
... |
Prompt the user to select a link from a list to open. | def prompt_and_select_link(self):
"""
Prompt the user to select a link from a list to open.
Return the link that was selected, or ``None`` if no link was selected.
"""
data = self.get_selected_item()
url_full = data.get('url_full')
permalink = data.get('permalink... |
Attempt to copy the selected URL to the user s clipboard | def copy_to_clipboard(self, url):
"""
Attempt to copy the selected URL to the user's clipboard
"""
if url is None:
self.term.flash()
return
try:
clipboard_copy(url)
except (ProgramError, OSError) as e:
_logger.exception(e)
... |
Open a prompt to navigate to a different subreddit or comment | def prompt(self):
"""
Open a prompt to navigate to a different subreddit or comment"
"""
name = self.term.prompt_input('Enter page: /')
if name:
# Check if opening a submission url or a subreddit url
# Example patterns for submissions:
# co... |
Open an instance of the inbox page for the logged in user. | def open_inbox_page(self, content_type):
"""
Open an instance of the inbox page for the logged in user.
"""
from .inbox_page import InboxPage
with self.term.loader('Loading inbox'):
page = InboxPage(self.reddit, self.term, self.config, self.oauth,
... |
Open an instance of the subscriptions page with the selected content. | def open_subscription_page(self, content_type):
"""
Open an instance of the subscriptions page with the selected content.
"""
from .subscription_page import SubscriptionPage
with self.term.loader('Loading {0}s'.format(content_type)):
page = SubscriptionPage(self.redd... |
Open an instance of the submission page for the given submission URL. | def open_submission_page(self, url=None, submission=None):
"""
Open an instance of the submission page for the given submission URL.
"""
from .submission_page import SubmissionPage
with self.term.loader('Loading submission'):
page = SubmissionPage(self.reddit, self.t... |
Open an instance of the subreddit page for the given subreddit name. | def open_subreddit_page(self, name):
"""
Open an instance of the subreddit page for the given subreddit name.
"""
from .subreddit_page import SubredditPage
with self.term.loader('Loading subreddit'):
page = SubredditPage(self.reddit, self.term, self.config,
... |
Clear the terminal screen and redraw all of the sub - windows | def draw(self):
"""
Clear the terminal screen and redraw all of the sub-windows
"""
n_rows, n_cols = self.term.stdscr.getmaxyx()
if n_rows < self.term.MIN_HEIGHT or n_cols < self.term.MIN_WIDTH:
# TODO: Will crash when you try to navigate if the terminal is too
... |
Draw the title bar at the top of the screen | def _draw_header(self):
"""
Draw the title bar at the top of the screen
"""
n_rows, n_cols = self.term.stdscr.getmaxyx()
# Note: 2 argument form of derwin breaks PDcurses on Windows 7!
window = self.term.stdscr.derwin(1, n_cols, self._row, 0)
window.erase()
... |
Draw the banner with sorting options at the top of the page | def _draw_banner(self):
"""
Draw the banner with sorting options at the top of the page
"""
n_rows, n_cols = self.term.stdscr.getmaxyx()
window = self.term.stdscr.derwin(1, n_cols, self._row, 0)
window.erase()
window.bkgd(str(' '), self.term.attr('OrderBar'))
... |
Loop through submissions and fill up the content page. | def _draw_content(self):
"""
Loop through submissions and fill up the content page.
"""
n_rows, n_cols = self.term.stdscr.getmaxyx()
window = self.term.stdscr.derwin(n_rows - self._row - 1, n_cols, self._row, 0)
window.erase()
win_n_rows, win_n_cols = window.getma... |
Draw the key binds help bar at the bottom of the screen | def _draw_footer(self):
"""
Draw the key binds help bar at the bottom of the screen
"""
n_rows, n_cols = self.term.stdscr.getmaxyx()
window = self.term.stdscr.derwin(1, n_cols, self._row, 0)
window.erase()
window.bkgd(str(' '), self.term.attr('HelpBar'))
... |
Accepts GET requests to http:// localhost: 6500/ and stores the query params in the global dict. If shutdown_on_request is true stop the server after the first successful request. | def do_GET(self):
"""
Accepts GET requests to http://localhost:6500/, and stores the query
params in the global dict. If shutdown_on_request is true, stop the
server after the first successful request.
The http request may contain the following query params:
- state ... |
Params: template_file ( text ): Path to an index. html template | def build_body(self, template_file=INDEX):
"""
Params:
template_file (text): Path to an index.html template
Returns:
body (bytes): THe utf-8 encoded document body
"""
if self.params['error'] == 'access_denied':
message = docs.OAUTH_ACCESS_DEN... |
Main entry point | def main():
"""Main entry point"""
# Squelch SSL warnings
logging.captureWarnings(True)
if six.PY3:
# These ones get triggered even when capturing warnings is turned on
warnings.simplefilter('ignore', ResourceWarning) # pylint:disable=E0602
# Set the terminal title
if os.geten... |
Use a number of methods to guess if the default webbrowser will open in the background as opposed to opening directly in the terminal. | def display(self):
"""
Use a number of methods to guess if the default webbrowser will open in
the background as opposed to opening directly in the terminal.
"""
if self._display is None:
if sys.platform == 'darwin':
# OS X won't set $DISPLAY unless x... |
Curses addch () method that fixes a major bug in python 3. 4. | def addch(window, y, x, ch, attr):
"""
Curses addch() method that fixes a major bug in python 3.4.
See http://bugs.python.org/issue21088
"""
if sys.version_info[:3] == (3, 4, 0):
y, x = x, y
window.addch(y, x, ch, attr) |
Curses does define constants for symbols ( e. g. curses. ACS_BULLET ). However they rely on using the curses. addch () function which has been found to be buggy and a general PITA to work with. By defining them as unicode points they can be added via the more reliable curses. addstr (). http:// bugs. python. org/ issue... | def get_arrow(self, likes):
"""
Curses does define constants for symbols (e.g. curses.ACS_BULLET).
However, they rely on using the curses.addch() function, which has been
found to be buggy and a general PITA to work with. By defining them as
unicode points they can be added via t... |
Required reading! http:// nedbatchelder. com/ text/ unipain. html | def clean(self, string, n_cols=None):
"""
Required reading!
http://nedbatchelder.com/text/unipain.html
Python 2 input string will be a unicode type (unicode code points).
Curses will accept unicode if all of the points are in the ascii range.
However, if any of the c... |
Unicode aware version of curses s built - in addnstr method. | def add_line(self, window, text, row=None, col=None, attr=None):
"""
Unicode aware version of curses's built-in addnstr method.
Safely draws a line of text on the window starting at position
(row, col). Checks the boundaries of the window and cuts off the text
if it exceeds the ... |
Shortcut for adding a single space to a window at the current position | def add_space(window):
"""
Shortcut for adding a single space to a window at the current position
"""
row, col = window.getyx()
_, max_cols = window.getmaxyx()
n_cols = max_cols - col - 1
if n_cols <= 0:
# Trying to draw outside of the screen bounds
... |
Overlay a message box on the center of the screen and wait for input. | def show_notification(self, message, timeout=None, style='Info'):
"""
Overlay a message box on the center of the screen and wait for input.
Params:
message (list or string): List of strings, one per line.
timeout (float): Optional, maximum length of time that the message... |
Prompt the user to select a link from a list to open. | def prompt_user_to_select_link(self, links):
"""
Prompt the user to select a link from a list to open.
Return the link that was selected, or ``None`` if no link was selected.
"""
link_pages = self.get_link_pages(links)
n = 0
while n in range(len(link_pages)):
... |
Given a list of links separate them into pages that can be displayed to the user and navigated using the 1 - 9 and 0 number keys. | def get_link_pages(links):
"""
Given a list of links, separate them into pages that can be displayed
to the user and navigated using the 1-9 and 0 number keys.
"""
link_pages = []
i = 0
while i < len(links):
link_page = []
while i < len(lin... |
Construct the dialog box to display a list of links to the user. | def get_link_page_text(link_page):
"""
Construct the dialog box to display a list of links to the user.
"""
text = ''
for i, link in enumerate(link_page):
capped_link_text = (link['text'] if len(link['text']) <= 20
else link['text'][:19... |
Open a media link using the definitions from the user s mailcap file. | def open_link(self, url):
"""
Open a media link using the definitions from the user's mailcap file.
Most urls are parsed using their file extension, but special cases
exist for websites that are prevalent on reddit such as Imgur and
Gfycat. If there are no valid mailcap definiti... |
Search through the mime handlers list and attempt to find the appropriate command to open the provided url with. | def get_mailcap_entry(self, url):
"""
Search through the mime handlers list and attempt to find the
appropriate command to open the provided url with.
Will raise a MailcapEntryNotFound exception if no valid command exists.
Params:
url (text): URL that will be checke... |
Open the given url using the default webbrowser. The preferred browser can specified with the $BROWSER environment variable. If not specified python webbrowser will try to determine the default to use based on your system. | def open_browser(self, url):
"""
Open the given url using the default webbrowser. The preferred browser
can specified with the $BROWSER environment variable. If not specified,
python webbrowser will try to determine the default to use based on
your system.
For browsers r... |
View a long block of text using an external pager/ viewer. The setting of the RTV_PAGER variable will be used if set otherwise the system s default pager is chosen finally defaulting to less if both RTV_PAGER and PAGER is unset in the calling environment. | def open_pager(self, data, wrap=None):
"""
View a long block of text using an external pager / viewer. The setting
of the RTV_PAGER variable will be used if set, otherwise the system's
default pager is chosen, finally defaulting to 'less' if both RTV_PAGER
and PAGER is unset in ... |
Open a file for editing using the system s default editor. | def open_editor(self, data=''):
"""
Open a file for editing using the system's default editor.
After the file has been altered, the text will be read back and the
HTML comment tag <!--INSRUCTIONS --> will be stripped. If an error
occurs inside of the context manager, the file wi... |
Pipe a block of text to urlview which displays a list of urls contained in the text and allows the user to open them with their web browser. | def open_urlview(self, data):
"""
Pipe a block of text to urlview, which displays a list of urls
contained in the text and allows the user to open them with their
web browser.
"""
urlview = os.getenv('RTV_URLVIEWER') or 'urlview'
command = shlex.split(urlview)
... |
Transform a window into a text box that will accept user input and loop until an escape sequence is entered. | def text_input(self, window, allow_resize=False):
"""
Transform a window into a text box that will accept user input and loop
until an escape sequence is entered.
If the escape key (27) is pressed, cancel the textbox and return None.
Otherwise, the textbox will wait until it is ... |
Display a text prompt at the bottom of the screen. | def prompt_input(self, prompt, key=False):
"""
Display a text prompt at the bottom of the screen.
Params:
prompt (string): Text prompt that will be displayed
key (bool): If true, grab a single keystroke instead of a full
string. This can be faster... |
Wrapper around prompt_input for simple yes/ no queries. | def prompt_y_or_n(self, prompt):
"""
Wrapper around prompt_input for simple yes/no queries.
"""
ch = self.prompt_input(prompt, key=True)
if ch in (ord('Y'), ord('y')):
return True
elif ch in (ord('N'), ord('n'), None):
return False
else:
... |
Attempt to intelligently strip excess whitespace from the output of a curses textpad. | def strip_textpad(text):
"""
Attempt to intelligently strip excess whitespace from the output of a
curses textpad.
"""
if text is None:
return text
# Trivial case where the textbox is only one line long.
if '\n' not in text:
return text.r... |
Remove instructional HTML comment tags inserted by RTV. | def strip_instructions(text):
"""
Remove instructional HTML comment tags inserted by RTV.
We used to use # to annotate comments, but it conflicted with the
header tag for markdown, which some people use to format their posts.
"""
# Pattern can span multiple lines, allows... |
In the beginning this always called touchwin (). However a bug was discovered in tmux when TERM was set to xterm - 256color where only part of the screen got redrawn when scrolling. tmux automatically sets TERM to screen - 256color but many people choose to override this in their tmux. conf or. bashrc file which can ca... | def clear_screen(self):
"""
In the beginning this always called touchwin(). However, a bug
was discovered in tmux when TERM was set to `xterm-256color`, where
only part of the screen got redrawn when scrolling. tmux automatically
sets TERM to `screen-256color`, but many people ch... |
Check if the given theme is compatible with the terminal | def check_theme(theme):
"""
Check if the given theme is compatible with the terminal
"""
terminal_colors = curses.COLORS if curses.has_colors() else 0
if theme.required_colors > terminal_colors:
return False
elif theme.required_color_pairs > curses.COLOR_PAIR... |
Check that the terminal supports the provided theme and applies the theme to the terminal if possible. | def set_theme(self, theme=None):
"""
Check that the terminal supports the provided theme, and applies
the theme to the terminal if possible.
If the terminal doesn't support the theme, this falls back to the
default theme. The default theme only requires 8 colors so it
sh... |
Return the object s fullname. | def fullname(self):
"""Return the object's fullname.
A fullname is an object's kind mapping like `t3` followed by an
underscore and the object's base36 id, e.g., `t1_c5s96e0`.
"""
by_object = self.reddit_session.config.by_object
return '{0}_{1}'.format(by_object[self.__... |
Approve object. | def approve(self):
"""Approve object.
This reverts a removal, resets the report counter, marks it with a
green check mark (only visible to other moderators) on the website view
and sets the approved_by attribute to the logged in user.
:returns: The json response from the server... |
Distinguish object as made by mod admin or special. | def distinguish(self, as_made_by='mod', sticky=False):
"""Distinguish object as made by mod, admin or special.
Distinguished objects have a different author color. With Reddit
Enhancement Suite it is the background color that changes.
`sticky` argument only used for top-level Comments.... |
Ignore future reports on this object. | def ignore_reports(self):
"""Ignore future reports on this object.
This prevents future reports from causing notifications or appearing
in the various moderation listing. The report count will still
increment.
"""
url = self.reddit_session.config['ignore_reports']
... |
Remove object. This is the moderator version of delete. | def remove(self, spam=False):
"""Remove object. This is the moderator version of delete.
The object is removed from the subreddit listings and placed into the
spam listing. If spam is set to True, then the automatic spam filter
will try to remove objects with similar attributes in the f... |
Remove ignoring of future reports on this object. | def unignore_reports(self):
"""Remove ignoring of future reports on this object.
Undoes 'ignore_reports'. Future reports will now cause notifications
and appear in the various moderation listings.
"""
url = self.reddit_session.config['unignore_reports']
data = {'id': se... |
Delete this object. | def delete(self):
"""Delete this object.
:returns: The json response from the server.
"""
url = self.reddit_session.config['del']
data = {'id': self.fullname}
response = self.reddit_session.request_json(url, data=data)
self.reddit_session.evict(self.reddit_sessi... |
Replace the body of the object with text. | def edit(self, text):
"""Replace the body of the object with `text`.
:returns: The updated object.
"""
url = self.reddit_session.config['edit']
data = {'thing_id': self.fullname,
'text': text}
response = self.reddit_session.request_json(url, data=data)
... |
Gild the Redditor or author of the content. | def gild(self, months=None):
"""Gild the Redditor or author of the content.
:param months: Specifies the number of months to gild. This parameter
is Only valid when the instance called upon is of type
Redditor. When not provided, the value defaults to 1.
:returns: True o... |
Hide object in the context of the logged in user. | def hide(self, _unhide=False):
"""Hide object in the context of the logged in user.
:param _unhide: If True, unhide the item instead. Use
:meth:`~praw.objects.Hideable.unhide` instead of setting this
manually.
:returns: The json response from the server.
"""
... |
Reply to object with the specified text. | def reply(self, text):
"""Reply to object with the specified text.
:returns: A Comment object for the newly created comment (reply).
"""
# pylint: disable=W0212
response = self.reddit_session._add_comment(self.fullname, text)
# pylint: enable=W0212
urls = [self.... |
Re - query to update object with latest values. Return the object. | def refresh(self):
"""Re-query to update object with latest values. Return the object.
Any listing, such as the submissions on a subreddits top page, will
automatically be refreshed serverside. Refreshing a submission will
also refresh all its comments.
In the rare case of a co... |
Report this object to the moderators. | def report(self, reason=None):
"""Report this object to the moderators.
:param reason: The user-supplied reason for reporting a comment
or submission. Default: None (blank reason)
:returns: The json response from the server.
"""
url = self.reddit_session.config['rep... |
Save the object. | def save(self, unsave=False):
"""Save the object.
:returns: The json response from the server.
"""
url = self.reddit_session.config['unsave' if unsave else 'save']
data = {'id': self.fullname,
'executed': 'unsaved' if unsave else 'saved'}
response = self... |
Vote for the given item in the direction specified. | def vote(self, direction=0):
"""Vote for the given item in the direction specified.
Note: votes must be cast by humans. That is, API clients proxying a
human's action one-for-one are OK, but bots deciding how to vote on
content or amplifying a human's vote are not. See the reddit rules ... |
Return the short permalink to the comment. | def _fast_permalink(self):
"""Return the short permalink to the comment."""
if hasattr(self, 'link_id'): # from /r or /u comments page
sid = self.link_id.split('_')[1]
else: # from user's /message page
sid = self.context.split('/')[4]
return urljoin(self.reddit_... |
Submission isn t set on __init__ thus we need to update it. | def _update_submission(self, submission):
"""Submission isn't set on __init__ thus we need to update it."""
submission._comments_by_id[self.name] = self # pylint: disable=W0212
self._submission = submission
if self._replies:
for reply in self._replies:
reply.... |
Return True when the comment is a top level comment. | def is_root(self):
"""Return True when the comment is a top level comment."""
sub_prefix = self.reddit_session.config.by_object[Submission]
return self.parent_id.startswith(sub_prefix) |
Return a list of the comment replies to this comment. | def replies(self):
"""Return a list of the comment replies to this comment.
If the comment is not from a submission, :meth:`replies` will
always be an empty list unless you call :meth:`refresh()
before calling :meth:`replies` due to a limitation in
reddit's API.
"""
... |
Return the Submission object this comment belongs to. | def submission(self):
"""Return the Submission object this comment belongs to."""
if not self._submission: # Comment not from submission
self._submission = self.reddit_session.get_submission(
url=self._fast_permalink)
return self._submission |
Request the url for a Message and return a Message object. | def from_id(reddit_session, message_id, *args, **kwargs):
"""Request the url for a Message and return a Message object.
:param reddit_session: The session to make the request with.
:param message_id: The ID of the message to request.
The additional parameters are passed directly into
... |
Collapse a private message or modmail. | def collapse(self):
"""Collapse a private message or modmail."""
url = self.reddit_session.config['collapse_message']
self.reddit_session.request_json(url, data={'id': self.name}) |
Mute the sender of this modmail message. | def mute_modmail_author(self, _unmute=False):
"""Mute the sender of this modmail message.
:param _unmute: Unmute the user instead. Please use
:meth:`unmute_modmail_author` instead of setting this directly.
"""
path = 'unmute_sender' if _unmute else 'mute_sender'
ret... |
Uncollapse a private message or modmail. | def uncollapse(self):
"""Uncollapse a private message or modmail."""
url = self.reddit_session.config['uncollapse_message']
self.reddit_session.request_json(url, data={'id': self.name}) |
Fetch and return the comments for a single MoreComments object. | def comments(self, update=True):
"""Fetch and return the comments for a single MoreComments object."""
if not self._comments:
if self.count == 0: # Handle 'continue this thread' type
return self._continue_comments(update)
# pylint: disable=W0212
child... |
Friend the user. | def friend(self, note=None, _unfriend=False):
"""Friend the user.
:param note: A personal note about the user. Requires reddit Gold.
:param _unfriend: Unfriend the user. Please use :meth:`unfriend`
instead of setting this parameter manually.
:returns: The json response from... |
Return a listing of the Submissions the user has downvoted. | def get_downvoted(self, *args, **kwargs):
"""Return a listing of the Submissions the user has downvoted.
:returns: get_content generator of Submission items.
The additional parameters are passed directly into
:meth:`.get_content`. Note: the `url` parameter cannot be altered.
A... |
Return information about this friend including personal notes. | def get_friend_info(self):
"""Return information about this friend, including personal notes.
The personal note can be added or overwritten with :meth:friend, but
only if the user has reddit Gold.
:returns: The json response from the server.
"""
url = self.reddit_s... |
Return a listing of the Submissions the user has upvoted. | def get_upvoted(self, *args, **kwargs):
"""Return a listing of the Submissions the user has upvoted.
:returns: get_content generator of Submission items.
The additional parameters are passed directly into
:meth:`.get_content`. Note: the `url` parameter cannot be altered.
As a ... |
Mark message ( s ) as read or unread. | def mark_as_read(self, messages, unread=False):
"""Mark message(s) as read or unread.
:returns: The json response from the server.
"""
ids = []
if isinstance(messages, Inboxable):
ids.append(messages.fullname)
elif hasattr(messages, '__iter__'):
... |
Return a UserList of Redditors with whom the user has blocked. | def get_blocked(self):
"""Return a UserList of Redditors with whom the user has blocked."""
url = self.reddit_session.config['blocked']
return self.reddit_session.request_json(url) |
Return a cached dictionary of the user s moderated reddits. | def get_cached_moderated_reddits(self):
"""Return a cached dictionary of the user's moderated reddits.
This list is used internally. Consider using the `get_my_moderation`
function instead.
"""
if self._mod_subs is None:
self._mod_subs = {'mod': self.reddit_session.... |
Return a list of MoreComments objects removed from tree. | def _extract_more_comments(tree):
"""Return a list of MoreComments objects removed from tree."""
more_comments = []
queue = [(None, x) for x in tree]
while len(queue) > 0:
parent, comm = queue.pop(0)
if isinstance(comm, MoreComments):
heappush(more... |
Return an edit - only submission object based on the id. | def from_id(reddit_session, subreddit_id):
"""Return an edit-only submission object based on the id."""
pseudo_data = {'id': subreddit_id,
'permalink': '/comments/{0}'.format(subreddit_id)}
return Submission(reddit_session, pseudo_data) |
Request the url and return a Submission object. | def from_url(reddit_session, url, comment_limit=0, comment_sort=None,
comments_only=False, params=None):
"""Request the url and return a Submission object.
:param reddit_session: The session to make the request with.
:param url: The url to build the Submission object from.
... |
Comment on the submission using the specified text. | def add_comment(self, text):
"""Comment on the submission using the specified text.
:returns: A Comment object for the newly created comment.
"""
# pylint: disable=W0212
response = self.reddit_session._add_comment(self.fullname, text)
# pylint: enable=W0212
self... |
Return forest of comments with top - level comments as tree roots. | def comments(self): # pylint: disable=E0202
"""Return forest of comments, with top-level comments as tree roots.
May contain instances of MoreComment objects. To easily replace these
objects with Comment objects, use the replace_more_comments method then
fetch this attribute. Use comme... |
Return a get_content generator for the submission s duplicates. | def get_duplicates(self, *args, **kwargs):
"""Return a get_content generator for the submission's duplicates.
:returns: get_content generator iterating over Submission objects.
The additional parameters are passed directly into
:meth:`.get_content`. Note: the `url` and `object_filter` ... |
Return available link flair choices and current flair. | def get_flair_choices(self, *args, **kwargs):
"""Return available link flair choices and current flair.
Convenience function for
:meth:`~.AuthenticatedReddit.get_flair_choices` populating both the
`subreddit` and `link` parameters.
:returns: The json response from the server.
... |
Lock thread. | def lock(self):
"""Lock thread.
Requires that the currently authenticated user has the modposts oauth
scope or has user/password authentication as a mod of the subreddit.
:returns: The json response from the server.
"""
url = self.reddit_session.config['lock']
... |
Mark as Not Safe For Work. | def mark_as_nsfw(self, unmark_nsfw=False):
"""Mark as Not Safe For Work.
Requires that the currently authenticated user is the author of the
submission, has the modposts oauth scope or has user/password
authentication as a mod of the subreddit.
:returns: The json response from ... |
Update the comment tree by replacing instances of MoreComments. | def replace_more_comments(self, limit=32, threshold=1):
"""Update the comment tree by replacing instances of MoreComments.
:param limit: The maximum number of MoreComments objects to
replace. Each replacement requires 1 API request. Set to None to
have no limit, or to 0 to make ... |
Set flair for this submission. | def set_flair(self, *args, **kwargs):
"""Set flair for this submission.
Convenience function that utilizes :meth:`.ModFlairMixin.set_flair`
populating both the `subreddit` and `item` parameters.
:returns: The json response from the server.
"""
return self.subreddit.set... |
Set Suggested Sort for the comments of the submission. | def set_suggested_sort(self, sort='blank'):
"""Set 'Suggested Sort' for the comments of the submission.
Comments can be sorted in one of (confidence, top, new, hot,
controversial, old, random, qa, blank).
:returns: The json response from the server.
"""
url = self.redd... |
Sticky a post in its subreddit. | def sticky(self, bottom=True):
"""Sticky a post in its subreddit.
If there is already a stickied post in the designated slot it will be
unstickied.
:param bottom: Set this as the top or bottom sticky. If no top sticky
exists, this submission will become the top sticky regar... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.