Created
September 6, 2015 19:00
-
-
Save diagonalfish/c5d106c330ee3d9dface to your computer and use it in GitHub Desktop.
Reddit bot init using praw2oauth
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import praw | |
from prawoauth2 import PrawOAuth2Server | |
import urllib2 | |
import json | |
print("Fetching list of scopes...") | |
scopes_json = urllib2.urlopen('https://www.reddit.com/api/v1/scopes').read() | |
scopes_data = json.loads(scopes_json) | |
print("\n== Bot info ==") | |
user_agent = raw_input("User agent: ") | |
app_key = raw_input("App key: ") | |
app_secret = raw_input("App secret: ") | |
scopes = [] | |
print("Scopes (type 'y' to include):") | |
for scope in scopes_data.keys(): | |
inp = raw_input("\t" + scopes_data[scope]["name"] + ": ") | |
if (inp == "y"): | |
scopes.append(scope) | |
reddit_client = praw.Reddit(user_agent=user_agent) | |
oauthserver = PrawOAuth2Server(reddit_client, app_key=app_key, | |
app_secret=app_secret, state=user_agent, | |
scopes=scopes) | |
# start the server, this will open default web browser | |
# asking you to authenticate | |
oauthserver.start() | |
codes = oauthserver.get_access_codes() | |
print("Access token: " + codes["access_token"]) | |
print("Refresh token: " + codes["refresh_token"]) | |
print("Scope: " + str(codes["scope"])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment