Fixed wordlist. Fixed whitelist.

tests
Frank 8 years ago
parent ef674d2774
commit ad5e252608

@ -8,6 +8,7 @@ import json
import yaml import yaml
import praw import praw
import random import random
import string
from re import sub from re import sub
from datetime import datetime, timedelta from datetime import datetime, timedelta
@ -73,10 +74,11 @@ log.debug("Deleting messages before {time}.".format(
whitelist = config.get('whitelist', []) whitelist = config.get('whitelist', [])
whitelist_ids = config.get('whitelist_ids', []) whitelist_ids = config.get('whitelist_ids', [])
if config.get('whitelist'): if whitelist:
log.debug("Keeping messages from subreddits {subs}".format( log.debug("Keeping messages from subreddits {subs}".format(
subs=', '.join(whitelist)) subs=', '.join(whitelist))
) )
whitelist = set([string.lower(subr) for subr in whitelist])
def get_sentence(): def get_sentence():
@ -87,14 +89,19 @@ try:
except ImportError: except ImportError:
# Module unavailable, use the default phrase # Module unavailable, use the default phrase
pass pass
os_wordlist = config.get('wordlist', '/usr/share/dict/words')
if config.get('replacement_format') == 'random':
wordlist = config.get('wordlist')
if not wordlist:
os_wordlist = '/usr/share/dict/words'
if os.name == 'posix' and os.path.isfile(os_wordlist): if os.name == 'posix' and os.path.isfile(os_wordlist):
# Generate a random string of words from our system's dictionary # Generate a random string of words from our system's dictionary
fh = open(os_wordlist) with open(os_wordlist) as fh:
words = fh.read().splitlines() wordlist = fh.read().splitlines()
fh.close() if wordlist:
def get_sentence(): def get_sentence():
return ' '.join(random.sample(words, random.randint(50,75))) return ' '.join(random.sample(wordlist, min(len(wordlist),
random.randint(50,75))))
def get_things(after=None): def get_things(after=None):
@ -130,7 +137,7 @@ def remove_things(things):
if thing_time < end_time: if thing_time < end_time:
continue continue
if str(thing.subreddit).lower() in config.get('whitelist', []) \ if str(thing.subreddit).lower() in whitelist \
or thing.id in config.get('whitelist_ids', []): or thing.id in config.get('whitelist_ids', []):
continue continue

@ -72,7 +72,8 @@ replacement_format: random
# See: https://docs.python.org/3/library/logging.html#logging-levels # See: https://docs.python.org/3/library/logging.html#logging-levels
debug: DEBUG debug: DEBUG
# Define your own wordlist to use as substitution text # Define your own wordlist to use as substitution text when
wordlist: False # replacement_format == random
wordlist: []
# vim: syntax=yaml ts=2 # vim: syntax=yaml ts=2

Loading…
Cancel
Save