From ef0e933a7b810ab8804ce2fa593faebb9c62a3f2 Mon Sep 17 00:00:00 2001 From: dragsubil Date: Fri, 13 May 2016 21:33:28 +0530 Subject: [PATCH] Major readme update, couple of backslashes removed In Readme.md: - Updated the readme to include instructions for Windows users. - Added instructions for OAuth2 (copied from inside the get_secret.py with some modifications). - Added a warning for possible future deprecation of the password based authentication. In shreddit.py: - removed \ which was used for wrapping in the next line. Used paranthesis and '''multiline string''' where needed. In requirements.txt: - changed praw==3.3.0 to 3.5.0 --- README.md | 52 ++++++++++++++++++++++++++++++++++++++------ requirements.txt | 2 +- shreddit.py | 9 ++++---- shreddit.yml.example | 4 ++-- 4 files changed, 53 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 5a3073d..238dd85 100644 --- a/README.md +++ b/README.md @@ -7,26 +7,36 @@ YAML Upgrade **Note! Important! The latest version uses YAML format over the old simpleconfigparser! This means you'll have to migrate your config file to yaml!** +User Login deprecation +-------------------- + +Reddit intends to disable username-password based authentication to access its APIs in the near future. You can specify your username and password in the `shreddit.yml` or the `praw.ini` to make it work **FOR NOW**. But consider looking at the [OAuth2 instructions](#oauth2-instructions) if you intend to use this program in the future. + Description ----------- -Shreddit is a Python command line program which will take a user's post history on the website Reddit (http://reddit.com) and after having the user edit a config file will systematically go through the user's history deleting one post/submission at a time until only those whitelisted remain. -Note: When it became known that post edits were *not* saved but post deletions *were* saved code was added to edit your post prior to deletion. In fact you can actually turn off deletion all together and just have lorem ipsum (or a message about Shreddit) but this will increase how long it takes the script to run as it will be going over all of your messages every run! +Shreddit is a Python command line program which will take a user's post history on the website [Reddit](http://reddit.com) and after having the user edit a config file will systematically go through the user's history deleting one post/submission at a time until only those whitelisted remain. + +**Note:** When it became known that post edits were *not* saved but post deletions *were* saved, code was added to edit your post prior to deletion. In fact you can actually turn off deletion all together and just have lorem ipsum (or a message about Shreddit) but this will increase how long it takes the script to run as it will be going over all of your messages every run! + Basically it lets you maintain your normal reddit account while having your history scrubbed after a certain amount of time. -Installation +Installation ([Click here for Windows instructions](#for-windows-users)) ----------- The way I personally install Shreddit is via a handy tool called `virtualenv` which may come with your package manager or may be a part of your Python package in your distro (have a search if you can't find it). Both Python 2 and 3 are supported. 1. Clone the repository 2. Enter the repository's directory and run `virtualenv .` (this creates a virtual environment) -3. Run the following command, you must run this *every time* you wish to run the script `source ./bin/activate` -4. This installs the required modules locally to your Shreddit virtual environment `pip install -r requirements.txt` -5. Copy `shreddit.cfg.example` to something else and edit it to your liking. -6. Run `python shreddit.py -c YOUR_CONFIG_FILE.cfg`. +3. Run the following command, you must run this *every time* you wish to run the script `source ./bin/activate`. +4. This installs the required modules locally to your Shreddit virtual environment `pip install -r requirements.txt`. +5. Copy `shreddit.yml.example` to something else and edit it to your liking. + - Make sure you specify your username and password in the file. + - See the [OAuth2 instructions](#oauth2-instructions) if you don't want to use username-password based authentication. +6. Run `python shreddit.py -c YOUR_CONFIG_FILE.yml`. Alternatively try to run `./install.sh` and it will attempt to do it all for you. + Notes: - The script *does* work with Python versions 2 and 3 but people often get in a mess with pip versions, python versions and virtulenv versions. Make sure that your Python/pip/virtualenv are all the same version. If you ran the above code it *should* work as stated. @@ -49,6 +59,34 @@ Cron examples If for some reason you get an error saying `source: not found` in your logs, change `source` to `.`. The source command would become `. bin/activate`. This is caused by your cron jobs running in shell, not bash, and the source command is a dot. +For Windows users +----------------- +1. Make sure you have python installed. [Click here for the Python download page](https://www.python.org/downloads/). + - **Note:** Install either `python 2.x` or `python 3.x`, not both. +2. Clone the repository (or download and extract the [zip file](https://github.com/dragsubil/Shreddit/archive/master.zip)) +3. Open command prompt and type `cd ` +4. Type `pip install -r requirements.txt` to download and install the required additional modules. +5. Open the `shreddit.yml.example` and edit it to your liking and rename the file to `your-config-filename.yml`. + - Make sure you specify your username and password in the file. + - See the [OAuth2 instructions](#oauth2-instructions) if you don't want to use username-password based authentication. +6. Type `python shreddit.py -c your-config-filename.yml` to run the program. + +OAuth2 Instructions +------------------- +1. Visit: https://www.reddit.com/prefs/apps +2. Click on 'Create app'. + - Fill in the name and select the 'script' option + - Under "redirect uri" put http://127.0.0.1:65010 +3. Copy from or rename `praw.ini.example` to `praw.ini` and open it. Enter the values from the Reddit page. + - oauth\_client\_id = { The ID displayed next to the icon thingy (under "personal use script") } + - oauth\_client\_secret = { The secret } + - oauth\_redirect\_uri = http://127.0.0.1:65010 + - Save the file. +4. Run `python get_secret.py` in the command prompt. +5. Your browser will open to a page on Reddit listing requested permissions. +6. Click 'Allow'. + + Caveats ----------- - Only your previous 1,000 comments are accessible on Reddit. So good luck deleting the others. There may be ways to hack around this via iterating using sorting by top/best/controversial/new but for now I am unsure. I believe it best to set the script settings and run it as a cron job and then it won't be a problem unless you post *a lot*. I do, however, think that it may be a caching issue and perhaps after a certain time period your post history would, once again, become available as a block of 1,000. So you needn't despair yet! diff --git a/requirements.txt b/requirements.txt index 88d619f..1f3ff5c 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,6 +1,6 @@ backports-abc==0.4 decorator==4.0.6 -praw==3.3.0 +praw==3.5.0 PyYAML==3.11 requests==2.8.1 six==1.10.0 diff --git a/shreddit.py b/shreddit.py index 0c19efc..1e744c9 100755 --- a/shreddit.py +++ b/shreddit.py @@ -11,8 +11,8 @@ import praw from re import sub from random import shuffle, randint from datetime import datetime, timedelta -from praw.errors import InvalidUser, InvalidUserPass, RateLimitExceeded, \ - HTTPException, OAuthAppRequired +from praw.errors import (InvalidUser, InvalidUserPass, RateLimitExceeded, + HTTPException, OAuthAppRequired) from praw.objects import Comment, Submission logging.basicConfig(stream=sys.stdout) @@ -24,6 +24,7 @@ try: except ImportError: def get_sentence(): return '''I have been Shreddited for privacy!''' + os_wordlist = '/usr/share/dict/words' if os.name == 'posix' and os.path.isfile(os_wordlist): # Generate a random string of words from our system's dictionary @@ -69,8 +70,8 @@ try: r.refresh_access_information() log.debug("Logged in with OAuth.") except (HTTPException, OAuthAppRequired) as e: - log.warning("You should migrate to OAuth2 using get_secret.py before \ - Reddit disables this login method.") + log.warning('''You should migrate to OAuth2 using get_secret.py before + Reddit disables this login method.''') try: try: r.login(config['username'], config['password']) diff --git a/shreddit.yml.example b/shreddit.yml.example index 012850e..f23bf0d 100644 --- a/shreddit.yml.example +++ b/shreddit.yml.example @@ -2,8 +2,8 @@ # Login details for Reddit. Fill out if you don't wish # to be prompted for a login every time you run Shreddit. ### NOTE: This may be deprecated as you can specify in praw.ini instead -username: null -password: null +username: +password: # How many hours of comments you want to keep # 24 hours in a day,