From 75c9f0e9872ccf8dcc43e1905707b54a9ec55db8 Mon Sep 17 00:00:00 2001 From: x89 Date: Sun, 22 Mar 2015 08:49:36 +0000 Subject: [PATCH] Improved get_sentence syntax, works on non-unix systems --- shreddit.py | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/shreddit.py b/shreddit.py index 910b32d..6543e75 100755 --- a/shreddit.py +++ b/shreddit.py @@ -15,20 +15,19 @@ from praw.objects import Comment, Submission try: from loremipsum import get_sentence # This only works on Python 2 except ImportError: - if os.name == 'posix': - try: - # Try to generate a random string of words - fh = open('/usr/share/dict/words') - words = fh.read().splitlines() - fh.close() - shuffle(words) - - def get_sentence(): - return ' '.join(words[:randint(50, 150)]) - except IOError: - def get_sentence(): - return '''I have been Shreddited for privacy!\n\n\ - https://github.com/x89/Shreddit/''' + 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 + fh = open(os_wordlist) + words = fh.read().splitlines() + fh.close() + shuffle(words) + def get_sentence(): + return ' '.join(words[:randint(50, 150)]) + +assert get_sentence parser = argparse.ArgumentParser() parser.add_argument( @@ -106,7 +105,7 @@ else: for thing in things: thing_time = datetime.fromtimestamp(thing.created_utc) - # Exclude items from being deleted unless past X hours. + # Exclude items from being deleted unless past X hours. after_time = datetime.utcnow() - timedelta(hours=hours) if thing_time > after_time: if thing_time + timedelta(hours=nuke_hours) < datetime.utcnow():