Added word filtering from grumbulon's fork. Plan to eventually make this regenerate the post instead of just replacing the text
This commit is contained in:
parent
50fe24c4e4
commit
b5b9a898c4
|
@ -13,3 +13,4 @@ __pycache__/
|
||||||
config.json
|
config.json
|
||||||
venv/
|
venv/
|
||||||
*.log
|
*.log
|
||||||
|
filter.txt
|
|
@ -0,0 +1,5 @@
|
||||||
|
put
|
||||||
|
bad
|
||||||
|
words
|
||||||
|
in
|
||||||
|
filter.txt
|
11
functions.py
11
functions.py
|
@ -56,6 +56,15 @@ def make_sentence(output, cfg):
|
||||||
elif cfg['mention_handling'] == 0:
|
elif cfg['mention_handling'] == 0:
|
||||||
sentence = re.sub(r"\S*@\u200B\S*\s?", "", sentence)
|
sentence = re.sub(r"\S*@\u200B\S*\s?", "", sentence)
|
||||||
|
|
||||||
|
# optionally remove filtered words
|
||||||
|
if cfg['word_filter'] == 1:
|
||||||
|
try:
|
||||||
|
fp = open('./filter.txt')
|
||||||
|
for word in fp:
|
||||||
|
if word in sentence:
|
||||||
|
sentence = sentence.replace(word, "[REDACTED]")
|
||||||
|
finally:
|
||||||
|
fp.close()
|
||||||
output.send(sentence)
|
output.send(sentence)
|
||||||
|
|
||||||
|
|
||||||
|
@ -64,7 +73,7 @@ def make_toot(cfg):
|
||||||
pin, pout = multiprocessing.Pipe(False)
|
pin, pout = multiprocessing.Pipe(False)
|
||||||
p = multiprocessing.Process(target=make_sentence, args=[pout, cfg])
|
p = multiprocessing.Process(target=make_sentence, args=[pout, cfg])
|
||||||
p.start()
|
p.start()
|
||||||
p.join(300) # wait 5 seconds to get something
|
p.join(5) # wait 5 seconds to get something
|
||||||
if p.is_alive(): # if it's still trying to make a toot after 5 seconds
|
if p.is_alive(): # if it's still trying to make a toot after 5 seconds
|
||||||
p.terminate()
|
p.terminate()
|
||||||
p.join()
|
p.join()
|
||||||
|
|
Loading…
Reference in New Issue