prawdditions.patch

This submodule contains functions that directly add attributes to PRAW models. To prevent conflicts with future PRAW additions, the models will not be modified without a call to patch(). Furthermore, the additions can be removed with a call to unpatch().

prawdditions.patch.patch

prawdditions.patch.patch()

Apply new methods to classes.

prawdditions.patch.unpatch

prawdditions.patch.unpatch()

Remove added methods.

Patched Functions

prawdditions.patch.message.message

prawdditions.patch.message.message(self, to: Union[praw.models.reddit.redditor.Redditor, praw.models.reddit.subreddit.Subreddit, str], title: str, body: str, from_sr: Union[praw.models.reddit.subreddit.Subreddit, str, None] = None) → praw.models.reddit.message.Message

Abstract function for sending out a message via string.

Note

Adds attribute message to praw.Reddit.

Parameters:
  • to – Destination of the message.
  • title – The subject line of the message.
  • body – The body of the message.
  • from_sr – A Subreddit instance of string to send the message from. By default the message originates from the user.
Returns:

An instance of praw.models.Message.

Example code:

import prawdditions.patch
reddit = praw.Reddit(client_id='CLIENT_ID',
                     client_secret="CLIENT_SECRET",
                     password='PASSWORD',
                     user_agent='USERAGENT', username='USERNAME')
prawdditions.patch.patch()
reddit.message('username','title','body')

prawdditions.patch.update.update

prawdditions.patch.update.update(self, transformation: Callable[str, str], reason: Optional[str] = None) → None

Safely update a page based on its current content.

Note

Adds attribute update to praw.models.WikiPage.

Parameters:
  • transformation – A function taking the previous content as its sole parameter and returning the new content.
  • reason – (Optional) The reason for the revision.

Example code:

import prawdditions.patch
reddit = praw.Reddit(client_id='CLIENT_ID',
                     client_secret="CLIENT_SECRET",
                     password='PASSWORD',
                     user_agent='USERAGENT', username='USERNAME')
prawdditions.patch.patch()
def transform(content: str) -> str:
    return content + " test"
page = next(iter(reddit.subreddit('test').wiki))
page.update(transform)