from setup import * programname = 'FRIENDREQUESTS' userdatadir, userlist, config, minimize, approval = setup(programname) def execute(): try: maxrequests = int(config[programname]['maxrequests']) print("Handling up to "+ str(maxrequests) + " requests") tsleep(5) except: print("Invalid settings. Please check settings and try again.") tsleep(5) return 0 driver, selecteduser=restart_browser(userdatadir, userlist) # ANY RETURN 0 AFTER THIS POINT WILL REQUIRE DRIVER.QUIT TO BE CALLED FIRST BEFORE PROCEEDING, TO PREVENT POSSIBLE MEMORY LEAK if minimize == 1: driver.minimize_window() print(selecteduser) try: driver.get('https://www.facebook.com/friends/requests') except: traceback.print_exc() # CHECK IF YOU ARE LOGGED IN if "login" in driver.current_url: print("Not logged in. Please make sure you are logged in.") tsleep(5) driver.quit() return 0 # YOU HAVE LOGGED IN AT THIS POINT -- MAIN PROGRAM EXECUTION STARTS HERE try: action = int(config[programname]["action"]) except: action = 0 # CHOOSE: ACCEPT OR REJECT REQUEST? reqs = '' if action == 1: print("Accepting friend requests") reqs = driver.find_elements(By.XPATH, "//*[contains(@class,'om3e55n1 g4tp4svg alzwoclg jez8cy9q jcxyg2ei i85zmo3j sr926ui1 jl2a5g8c k7n6ui8p b41d885q hmqrhxox got7tec9 frfouenu bonavkto djs4p424 r7bn319e bdao358l aesu6q9g e4ay1f3w n75z76so ed17d2qt')]") elif action == 2: print("Rejecting friend requests") reqs = driver.find_elements(By.XPATH, "//*[contains(@class,'om3e55n1 g4tp4svg alzwoclg jez8cy9q jcxyg2ei i85zmo3j sr926ui1 jl2a5g8c k7n6ui8p b41d885q hmqrhxox got7tec9 frfouenu bonavkto djs4p424 r7bn319e bdao358l aesu6q9g e4ay1f3w a5wdgl2o ed17d2qt')]") else: print("Invalid settings. Please check settings and try again.") tsleep(5) driver.quit() return 0 print(reqs) links = driver.find_elements(By.XPATH, "//*[contains(@class,'qi72231t o9w3sbdw nu7423ey tav9wjvu flwp5yud tghlliq5 gkg15gwv s9ok87oh s9ljgwtm lxqftegz bf1zulr9 frfouenu bonavkto djs4p424 r7bn319e bdao358l fsf7x5fv tgm57n0e jez8cy9q s5oniofx m8h3af8h l7ghb35v kjdc1dyq kmwttqpk dnr7xe2t aeinzg81 srn514ro oxkhqvkx rl78xhln nch0832m om3e55n1 cr00lzj9 rn8ck1ys s3jn8y49 g4tp4svg jl2a5g8c f14ij5to l3ldwz01 icdlwmnq h8391g91 m0cukt09 kpwa50dg ta68dy8c b6ax4al1')]") count = 0 # maximum friend requests accepted at a time specified in ini for req, link in zip(reqs, links): count += 1 print("Friend request!") print(req) print(req.text) url = link.get_attribute('href') print(url) elmt=req.find_element(By.XPATH, "./../../../../../..") txt=elmt.text lines=txt.split('\n') print(lines) # print(elmt.text) serverid = config['DEFAULT']['serverid'] tsleep(15) #just in case you want to change your mind... webdriver.ActionChains(driver).move_to_element(req).perform() webdriver.ActionChains(driver).move_to_element(req).click().perform() db['friend_requests'].insert({"datetime":datetime.now(), "name": lines[0], "page_link": url, "request_age": lines[1], "server_ID": serverid, "profile": selecteduser}) print("Completed") if count == maxrequests: break print("Program has completed execution") tsleep(5) driver.quit() if approval == 1: execute()