From 2a1e2fb0a551ba2c1ea9f1ca2010649332d28ac9 Mon Sep 17 00:00:00 2001 From: Scott Date: Mon, 28 Nov 2016 16:17:15 -0600 Subject: [PATCH] Makes it easier for users to get the default config --- .gitignore | 1 + setup.py | 6 +-- shreddit/app.py | 11 ++++- shreddit/shreddit.yml.example | 83 +++++++++++++++++++++++++++++++++++ 4 files changed, 97 insertions(+), 4 deletions(-) create mode 100644 shreddit/shreddit.yml.example diff --git a/.gitignore b/.gitignore index e336702..84bf6ca 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ shreddit.yml praw.ini +Makefile # Docs docs/_build/ diff --git a/setup.py b/setup.py index c6b8ee3..fc369f2 100644 --- a/setup.py +++ b/setup.py @@ -4,7 +4,7 @@ from setuptools import setup from codecs import open from os import path -VERSION = "2.0.0" +VERSION = "2.1.0" DESCRIPTION = " Remove your comment history on Reddit as deleting an account does not do so." here = path.abspath(path.dirname(__file__)) @@ -27,8 +27,8 @@ setup( "Intended Audience :: End Users/Desktop", "Programming Language :: Python"], packages=["shreddit"], - install_requires=["arrow", "backports-abc", "decorator", "praw", "PyYAML", - "requests", "six", "tornado", "update-checker", "wheel"], + install_requires=["arrow", "backports-abc", "praw", "PyYAML", "requests", "six", "tornado"], + package_data={"shreddit": ["shreddit.yml.example"]}, entry_points={ "console_scripts": [ "shreddit=shreddit.app:main" diff --git a/shreddit/app.py b/shreddit/app.py index 0eeaca8..b25c2d5 100644 --- a/shreddit/app.py +++ b/shreddit/app.py @@ -3,6 +3,8 @@ import argparse import yaml import logging +import os +import pkg_resources from shreddit import default_config from shreddit.oauth import oauth_test from shreddit.shredder import Shredder @@ -19,7 +21,14 @@ def main(): oauth_test(args.praw) return - with open(args.config or "shreddit.yml") as fh: + config_filename = args.config or "shreddit.yml" + if not os.path.isfile(config_filename): + print("No configuration file could be found. Paste the following into a file called \"shreddit.yml\" and " \ + "try running shreddit again:\n\n") + print(pkg_resources.resource_string("shreddit", "shreddit.yml.example")) + return + + with open(config_filename) as fh: # Not doing a simple update() here because it's preferable to only set attributes that are "whitelisted" as # configuration options in the form of default values. user_config = yaml.safe_load(fh) diff --git a/shreddit/shreddit.yml.example b/shreddit/shreddit.yml.example new file mode 100644 index 0000000..38088a8 --- /dev/null +++ b/shreddit/shreddit.yml.example @@ -0,0 +1,83 @@ +--- +# 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: +password: + +# How many hours of comments you want to keep +# 24 hours in a day, +# 168 hours in a week, +# 672 hours in two fortnights, +# 720 hours in a month (30 days), +# 8766 hours in a year (365.25 days) +hours: 24 + +# Max score, higher than this and it'll be kept. +max_score: 100 + +# Options: new, top, controversial, more? +sort: new + +# Enables print statements to notify you of what's going on +verbose: True + +# Removes your vote before deleting the item +clear_vote: False + +# Options: comments, submitted, overview +# See: https://github.com/mellort/reddit_api/blob/master/reddit/objects.py#L359 +# Overview: both submissions and comments. Comments / Submitted are as expected +item: overview + +# Anything in this list won't be deleted, coma delimited +# spaces should work as .strip() is called after splitting +# on comma. +whitelist: [AskScience, TheCulture, redditdev, programming, charity, netsec] + +# If you want any specific posts to be whitelisted stick 'em in here +whitelist_ids: [] + +# If you set this then no editing or deleting will be done +# but the output from the program will be shown as an example +trial_run: False + +# Don't delete but *do* edit, could prove... interesting to see a comment +# with 5000 upvotes and it's just a lorem ipsum! +edit_only: False + +# Ignore distinguished comments. +whitelist_distinguished: True + +# Ignore gilded (gold) comments +whitelist_gilded: True + +# Delete everything older that this date, **This ignores whitelists**. +# Can be used as a second deletion, as in "delete items older than 24 hours +# except on whitelisted subreddits but after 3 months delete everything. +nuke_hours: 720 + +# Save a copy to disk of comments and posts before deleting them. +keep_a_copy: False +save_directory: /tmp + +# Replacement text format +# Defines what you want to edit deleted content with pre-deletion (to ensure +# it's not saved in their database). +# Default: Random string. But this can be detected as spam in some cases. +# options: [random, dot, "user entered string"] +replacement_format: random + +# Debug level, how much output you want +# See: https://docs.python.org/3/library/logging.html#logging-levels +debug: DEBUG + +# Define your own wordlist to use as substitution text when +# replacement_format == random +wordlist: [] + +# Batch cooldown +# This controls how long (in seconds) to wait between each set of 1000 deletions. +batch_cooldown: 10 + +# vim: syntax=yaml ts=2