From 2b90ba8aea6267a4f9bb74f0f0ed11ab2dfbedcd Mon Sep 17 00:00:00 2001 From: Scott Date: Tue, 6 Dec 2016 00:35:00 -0600 Subject: [PATCH] Removes outdated OAuth helper scripts --- get_secret.py | 68 ----------------------------------------------- shreddit/oauth.py | 22 --------------- 2 files changed, 90 deletions(-) delete mode 100755 get_secret.py delete mode 100644 shreddit/oauth.py diff --git a/get_secret.py b/get_secret.py deleted file mode 100755 index 7d340a4..0000000 --- a/get_secret.py +++ /dev/null @@ -1,68 +0,0 @@ -#!/usr/bin/env python -''' -So I heard you want to use OAuth2? This is a helper tool that gets the -authenticaton code for you and fires it into praw.ini. - -How to use: - - Visit: https://www.reddit.com/prefs/apps - - Create new "script", under "redirect uri" put http://127.0.0.1:65010 - - Open praw.ini - - oauth_client_id = { The ID displayed under the icon thingy } - - oauth_client_secret = { The secret } - - oauth_redirect_uri = http://127.0.0.1:65010 - - Run this script - - Your browser will open to a page on Reddit listing requested perms - - Click permit -''' - -import praw -import webbrowser -from warnings import warn -from praw.errors import HTTPException, OAuthAppRequired -from tornado import gen, web -from tornado.ioloop import IOLoop -from tornado.httpserver import HTTPServer - -r = praw.Reddit('Shreddit refresh token grabber') - - -class Page(web.RequestHandler): - def get(self): - code = self.get_argument("code", default=None, strip=False) - self.write("Success! Your code: %s
\ - It will now be appended to praw.ini and you \ - should be able to enjoy Shreddit without storing \ - your user / pass anywhere." % code) - IOLoop.current().stop() - self.login(code) - - def login(self, code): - deets = r.get_access_information(code) - print("oauth_refresh_token: %s" % deets['refresh_token']) - r.set_access_credentials(**deets) - with open('praw.ini', mode='a') as fh: - fh.write('oauth_refresh_token = %s' % deets['refresh_token']) - print("Refresh token written to praw.ini") - -application = web.Application([(r"/", Page)]) - -try: - r.refresh_access_information() -except HTTPException: - url = r.get_authorize_url('uniqueKey', ['identity', 'read', 'vote', 'edit', 'history'], True) - try: - print("Opening url: %s" % url) - webbrowser.open(url, new=2) - except NameError: - warn('''Couldn't open URL: %s\n please do so manually''' % url) - server = HTTPServer(application) - server.listen(65010) - IOLoop.current().start() - -if r.user == None: - print("Failed to log in. Something went wrong!") -else: - print("Logged in as %s." % r.user) - -print() - diff --git a/shreddit/oauth.py b/shreddit/oauth.py deleted file mode 100644 index 8276c43..0000000 --- a/shreddit/oauth.py +++ /dev/null @@ -1,22 +0,0 @@ -"""This module contains a function that tests OAuth session validity. -""" -import os -import praw - - -def oauth_test(praw_ini): - if praw_ini: - # PRAW won't panic if the file is invalid, so check first - if not os.path.exists(praw_ini): - print("PRAW configuration file \"{}\" not found.".format(praw_ini)) - return - praw.settings.CONFIG.read(praw_ini) - r = praw.Reddit("Shreddit oauth test") - try: - r.refresh_access_information() - if r.is_oauth_session(): - print("Session is valid.") - else: - print("Session is not a valid OAuth session.") - except Exception as e: - print("Error encountered while checking credentials:\n{}".format(e))