-
Notifications
You must be signed in to change notification settings - Fork 0
Home
Note: These example are intended to be completed in order. While you are free to skip down to what you want to accomplish, please check the previous examples for any NameErrors you might encounter.
-
Import the package
import praw ```
-
Create the reddit object that everything(requires a user agent):
r = praw.Reddit(user_agent='example') ```
-
Logging in:
r.login('username', 'password') ```
-
Send a message (requires login):
r.compose_message('bboe', 'Subject Line', 'You are awesome!') ```
-
Mark all unread messages as read (requires login):
for msg in r.user.get_unread(limit=None): msg.mark_as_read() ```
-
Get the top submissions for r/python:
submissions = r.get_subreddit('python').get_top(limit=10) ```
-
Get comments from a given submission:
submission = submissions.next() submission.comments ```
-
Comment on a submission (requires login):
submission.add_comment('text') ```
-
Reply to a comment (requires login):
comment = submission.comments[0] comment.reply('test') ```
-
Voting (requires login):
item.upvote() item.downvote() item.clear_vote() ```
-
Deleting (requires login):
#item can be a comment or submission item.delete() ```
-
Saving a submission (requires login):
submission.save() submission.unsave() ```
-
Create a SELF submission (requires login):
r.submit('reddit_api_test', 'submission title', text='body') ```
-
Create a URL submission (requires login):
r.submit('reddit_api_test', 'Google!', url='http://google.com') ```
-
Get user karma:
user = r.get_redditor('ketralnis') user.link_karma user.comment_karma ```
-
Get saved links (requires login):
r.get_saved_links() ```
-
Get content newer than a comment or submission's id:
r.get_subreddit('python').get_top(limit=None, place_holder=submission.id) ```
-
(Un)subscribe to a subreddit (requires login):
r.get_subreddit('python').subscribe() r.get_subreddit('python').unsubscribe() ```
-
(Un)friend a user:
r.get_redditor('ketralnis').friend() r.get_redditor('ketralnis').unfriend() ```
-
Create a subreddit:
r.create_subreddit(short_title='MyIncredibleSubreddit', full_title='my Incredibly Cool Subreddit', description='It is incredible!') ```
-
Get flair mappings for a particular subreddit (requires mod privileges):
item = r.get_subreddit('python').flair_list().next() item['user'] item['flair_text'] item['flair_css_class'] ```
-
Set / update user flair (requires mod privileges):
r.get_subreddit('python').set_flair('bboe', 'text flair', 'css-class') ```
-
Clear user flair (requires mod privileges):
r.get_subreddit('python').set_flair('bboe') ```
-
Bulk set user flair (requires mod privileges):
flair_mapping = [{'user':'bboe', 'flair_text':'dev'}, {'user':'pyapitestuser3', 'flair_css_class':'css2'}, {'user':'pyapitestuser2', 'flair_text':'AWESOME', 'flair_css_class':'css'}] r.get_subreddit('python').set_flair_csv(flair_mapping) ```
-
Add flair templates (requires mod privileges):
r.get_subreddit('python').add_flair_template(text='editable', css_class='foo', text_editable=True) ```
-
Clear flair templates (requires mod privileges):
r.get_subreddit('python').clear_flair_templates() ```
- All of the listings (list of stories on subreddit, etc.) are generators,
not lists. If you need them to be lists, an easy way is to call
list()with your variable as the argument. - The default limit for fetching stories is 25. You can change this with the
limitparam. If you don't want a limit, setlimit=None. This will return an infinite generator that will continue fetching stories until reddit hiccups (I wouldn't expect more than ~300 stories).
- BBoe's Modutils that provides a few functions that are helpful to Reddit moderators.
- BBoe's Subreddit Stats is a tool to compute submission / comment statistics for a reddit community.
- Deimos's AutoModerator, a bot for automating straightforward reddit moderation tasks and improving upon the existing spam-filter.
- r.doqdoq, a website that displays reddit stories under the guise of Python or Java code. Source available on bitbucket.
- Reddit Notifier for Gnome3. Integrates with Unity and Gnome Shell to display new Reddit mail as it arrives.
- Link Unscripter, a bot for replying to posts (and comments, eventually) that contain javascript-required links, to provide non-javascript alternatives
- <Your Script Here> Send bboe a message and we'll add a link to your script. Alternatively add it yourself, and submit a pull request.
Note: The following use very outdated versions of the API. Don't expect them to work with the latest version.
- A comment tracker, that repeatedly looks at new reddit comments and can take an action if they meet a specified condition. The example use I gave is replying with an automated message if the body of a comment contains a certain word. (Novelty accounts, anyone?)
- An account cloner that given two logins and passwords, it will transfer all of the saved links and subscribed subreddits from the first account to the second.
- A comment generator that pulls comments from reddit, puts them in a Markov chain, and periodically outputs random statuses. The statuses can be viewed here.