Skip to content

Instantly share code, notes, and snippets.

@shrayasr
Last active August 9, 2020 08:33
Show Gist options
  • Save shrayasr/10005943 to your computer and use it in GitHub Desktop.
Save shrayasr/10005943 to your computer and use it in GitHub Desktop.
Updating sidebar content with PRAW

Updating reddit sidebar content with PRAW

PRAW is the AWESOME Reddit API Wrapper written in Python.

Download PRAW

pip install praw

Import PRAW

import praw

Get a handler to reddit, passing the user agent (important!)

r = praw.Reddit("sidebar updater by /u/helloworld")

Login

r.login("USERNAME","PASSWORD")

Define the subreddit name for use

sub = "subreddit"

Get the settings of the subreddit

settings = r.get_settings(sub)

Inside the settings object, there is a description field. This field will have the contents of the sidebar. Do whatever you want with it

sidebar_contents = settings['description']
sidebar_contents += "\n\nUpdated from script, yo!"

Update the settings

r.update_settings(r.get_subreddit(sub), description=sidebar_contents)

Go to the subreddit and marvel!

@impshum
Copy link

impshum commented Aug 9, 2020

Would be nice if this still worked.

That's I thought...

reddit.subreddit(target_subreddit).wiki['config/sidebar'].edit(sidebar_content)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment