rst_messages_list = []
if div.id not in parsed_messages:
rst_messages_list.append(div.text)
to this
rst_messages_list = []
if div.id in parsed_messages:
continue
rst_messages_list.append(div.text)
def send_message(message, xpaths):
FIREFOX_DRIVER.find_element_by_xpath(xpaths['textArea']).clear()
FIREFOX_DRIVER.find_element_by_xpath(xpaths['textArea']).send_keys(message)
FIREFOX_DRIVER.find_element_by_xpath(xpaths['submitMessage']).click()
That reduces your code drastically:
That reduces your code drastically:
if any(word in unique_message for word in bad_words):
send_message(message, xpaths)
if '/message1' in unique_message:
send_message("text to be sent", xpaths)
if '/message2' in unique_message:
send_message("2016 © me", xpaths)
if '/message3' in unique_message:
line = random.choice(open('jokes.txt').readlines())
send_message(line, xpaths)
Worth noting that since these are all if commands, you might send every one of these messages, for a message like "/message1 /message2 /message3 smeg" (assuming that smeg is on your list of bad_words). You should makeall but the secondfirst one on elifs, so that they're mutually exclusive and only one (or none) will run.