Skip to main content
added 4 characters in body
Source Link
SuperBiasedMan
  • 13.5k
  • 5
  • 37
  • 62
for unique_message in rst_messages_list:
    unique_message = unique_message.lower()
for unique_message in rst_messages_list:
    if any(word in unique_message for word in bad_words):
    
unique_message = unique_message.lower()
for unique_message in rst_messages_list:
    if any(word in unique_message for word in bad_words):
    
for unique_message in rst_messages_list:
    unique_message = unique_message.lower()
    if any(word in unique_message for word in bad_words):
    
added 6 characters in body
Source Link
SuperBiasedMan
  • 13.5k
  • 5
  • 37
  • 62
if any(word in unique_message for word in bad_words):
    send_message(message, xpaths)
ifelif '/message1' in unique_message:
    send_message("text to be sent", xpaths)
ifelif '/message2' in unique_message:
    send_message("2016 © me", xpaths)
ifelif '/message3' in unique_message:
    line = random.choice(open('jokes.txt').readlines())
    send_message(line, xpaths)
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)
if any(word in unique_message for word in bad_words):
    send_message(message, xpaths)
elif '/message1' in unique_message:
    send_message("text to be sent", xpaths)
elif '/message2' in unique_message:
    send_message("2016 © me", xpaths)
elif '/message3' in unique_message:
    line = random.choice(open('jokes.txt').readlines())
    send_message(line, xpaths)
added 35 characters in body
Source Link
SuperBiasedMan
  • 13.5k
  • 5
  • 37
  • 62
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.

rst_messages_list = []
if div.id not in parsed_messages:
    rst_messages_list.append(div.text)
    
rst_messages_list = []
if div.id in parsed_messages:
    continue
    
rst_messages_list.append(div.text)
def send_message(message):
    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:
    
    
if any(word in unique_message for word in bad_words):
    send_message(message)
if '/message1' in unique_message:
    send_message("text to be sent")
if '/message2' in unique_message:
    send_message("2016 © me")
if '/message3' in unique_message:
    line = random.choice(open('jokes.txt').readlines())
    send_message(line)

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 make the second one on elifs, so that they're mutually exclusive and only one (or none) will run.

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:

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 all but the first one elifs, so that they're mutually exclusive and only one (or none) will run.

Source Link
SuperBiasedMan
  • 13.5k
  • 5
  • 37
  • 62
Loading