Improved get_sentence syntax, works on non-unix systems

pteek-dump
x89 10 years ago
parent 8df4e34256
commit 75c9f0e987

@ -15,20 +15,19 @@ from praw.objects import Comment, Submission
try: try:
from loremipsum import get_sentence # This only works on Python 2 from loremipsum import get_sentence # This only works on Python 2
except ImportError: except ImportError:
if os.name == 'posix': def get_sentence():
try: return '''I have been Shreddited for privacy!'''
# Try to generate a random string of words os_wordlist = '/usr/share/dict/words'
fh = open('/usr/share/dict/words') if os.name == 'posix' and os.path.isfile(os_wordlist):
words = fh.read().splitlines() # Generate a random string of words from our system's dictionary
fh.close() fh = open(os_wordlist)
shuffle(words) words = fh.read().splitlines()
fh.close()
def get_sentence(): shuffle(words)
return ' '.join(words[:randint(50, 150)]) def get_sentence():
except IOError: return ' '.join(words[:randint(50, 150)])
def get_sentence():
return '''I have been Shreddited for privacy!\n\n\ assert get_sentence
https://github.com/x89/Shreddit/'''
parser = argparse.ArgumentParser() parser = argparse.ArgumentParser()
parser.add_argument( parser.add_argument(
@ -106,7 +105,7 @@ else:
for thing in things: for thing in things:
thing_time = datetime.fromtimestamp(thing.created_utc) 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) after_time = datetime.utcnow() - timedelta(hours=hours)
if thing_time > after_time: if thing_time > after_time:
if thing_time + timedelta(hours=nuke_hours) < datetime.utcnow(): if thing_time + timedelta(hours=nuke_hours) < datetime.utcnow():

Loading…
Cancel
Save