JSchmoe

YOUR IS THE SCRIPT THAT WILL END WORLD HUNGER

Dec 20th, 2016
138
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. from selenium import webdriver
  2. from selenium.webdriver.firefox.firefox_profile import FirefoxProfile
  3. import time
  4.  
  5. firefoxProfile = FirefoxProfile()
  6. ## Disable images
  7. firefoxProfile.set_preference('permissions.default.image', 2)
  8. ## Disable Flash
  9. firefoxProfile.set_preference('dom.ipc.plugins.enabled.libflashplayer.so',
  10.                               'false')
  11.  
  12. driver_freerice = webdriver.Firefox(firefoxProfile)
  13. driver_freerice.get("http://freerice.com/#/english-vocabulary")
  14.  
  15. driver_thesaurus = webdriver.Firefox()
  16. driver_thesaurus.set_page_load_timeout(3.5)
  17.  
  18. grains = 0
  19.  
  20. while True:
  21.     time.sleep(1.5)
  22.     word = driver_freerice.find_elements_by_xpath("//*[contains(text(), 'means:')]")[1].text.split()[0]
  23.  
  24.     answers = []
  25.     for answer in driver_freerice.find_elements_by_class_name("answer-item"):
  26.         answers.append((answer.text, answer))
  27.        
  28.     print "Current grains: "+str(grains)
  29.     print "Current word: "+word
  30.     print "Candidates:"
  31.     for a in answers: print "  "+a[0]
  32.  
  33.     try: driver_thesaurus.get("http://www.thesaurus.com/browse/"+word+"?s=t")
  34.     except Exception as e: pass
  35.  
  36.     try:
  37.         try: e = [driver_thesaurus.find_element_by_xpath('.//strong[@class = "ttl"]')]
  38.         except: e = []
  39.         for syn in driver_thesaurus.find_elements_by_xpath('.//span[@class = "text"]')+e:
  40.             for ans in answers:
  41.                 if syn.text == ans[0]:
  42.                     print "Gotcha! Found synonym: "+syn.text+"\n"
  43.                     ans[1].click()
  44.                     grains += 10
  45.                     raise Exception("woo")
  46.                    
  47.         print "Could not find synonym :(\n"
  48.        
  49.         answers[0][1].click()
  50.  
  51.     except Exception as e:
  52.         if str(e) == "woo": continue
  53.         else:
  54.             print str(e)
  55.             driver_freerice.get("http://freerice.com/#/english-vocabulary")
RAW Paste Data