Skip to content

Commit

Permalink
Optimise and minor bug fix random string generation
Browse files Browse the repository at this point in the history
  • Loading branch information
x89 committed Sep 30, 2016
1 parent 65fbf90 commit 92028f2
Showing 1 changed file with 20 additions and 21 deletions.
41 changes: 20 additions & 21 deletions shreddit.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
import json
import yaml
import praw
import random

from re import sub
from random import shuffle, randint
from datetime import datetime, timedelta
from praw.errors import (InvalidUser, InvalidUserPass, RateLimitExceeded,
HTTPException, OAuthAppRequired)
Expand All @@ -19,25 +19,6 @@
log = logging.getLogger(__name__)
log.setLevel(level=logging.DEBUG)

try:
from loremipsum import get_sentence # This only works on Python 2
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
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(
'-c',
Expand All @@ -63,7 +44,7 @@ def get_sentence():
r.config.store_json_result = True

if config.get('verbose', True):
log_level = config.get('debug', 'WARNING') # Default to WARNING only
log_level = config.get('debug', 'DEBUG')
log.setLevel(level=getattr(logging, log_level))

try:
Expand Down Expand Up @@ -98,6 +79,24 @@ def get_sentence():
)


def get_sentence():
return '''I have been Shreddited for privacy!'''
try:
# Provide a method that works on windows
from loremipsum import get_sentence
except ImportError:
# Module unavailable, use the default phrase
pass
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()
def get_sentence():
return ' '.join(random.sample(words, random.randint(50,75)))


def get_things(after=None):
limit = None
item = config.get('item', 'comments')
Expand Down

0 comments on commit 92028f2

Please sign in to comment.