like_posts.py 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. from setup import *
  2. programname = 'LIKEPOSTS'
  3. userdatadir, userlist, config, minimize, approval = setup(programname)
  4. def execute():
  5. try:
  6. maxlikes = int(config[programname]['maxlikecount'])
  7. print("Liking up to "+ str(maxlikes) + " posts")
  8. tsleep(5)
  9. except:
  10. print("Invalid settings. Please check settings and try again.")
  11. tsleep(5)
  12. return 0
  13. driver, selecteduser=restart_browser(userdatadir, userlist)
  14. if minimize == 1:
  15. driver.minimize_window()
  16. print(selecteduser)
  17. try:
  18. driver.get('https://www.facebook.com/friends/requests')
  19. except:
  20. traceback.print_exc()
  21. print("Can't get URL or invalid URL. Please check the URL and try again.")
  22. tsleep(5)
  23. driver.quit()
  24. return 0
  25. # CHECK IF YOU ARE LOGGED IN
  26. if "login" in driver.current_url:
  27. print("Not logged in. Please make sure you are logged in.")
  28. tsleep(5)
  29. driver.quit()
  30. return 0
  31. # YOU HAVE LOGGED IN AT THIS POINT -- MAIN PROGRAM EXECUTION STARTS HERE
  32. try:
  33. driver.get('https://www.facebook.com')
  34. except:
  35. print("Can't get URL or invalid URL. Please check the URL and try again.")
  36. tsleep(5)
  37. return 0
  38. maxscroll = math.ceil(maxlikes / 7) + 2
  39. for i in range(1,maxscroll):
  40. driver.execute_script("window.scrollBy(0,document.body.scrollHeight)")
  41. tsleep(2)
  42. req = driver.find_elements(By.XPATH, "//*[contains(@class,'bdao358l om3e55n1 g4tp4svg alzwoclg cqf1kptm gvxzyvdx aeinzg81 jg3vgc78 cgu29s5g i15ihif8 pdnn8mpk f1iqohp5 bmgto6uh f9xcifuu')]") #like btn
  43. reqs=[]
  44. for i in req:
  45. if i.text == "Like" or i.text == "讚":
  46. reqs.append(i)
  47. author = driver.find_elements(By.XPATH, "//*[contains(@class,'alzwoclg om3e55n1 mfclru0v')]")
  48. authors = []
  49. for a in author:
  50. if a.text != "":
  51. authors.append(a)
  52. tags = driver.find_elements(By.XPATH, "//*[contains(@class,'qi72231t nu7423ey n3hqoq4p r86q59rh b3qcqh3k fq87ekyn bdao358l fsf7x5fv rse6dlih s5oniofx m8h3af8h l7ghb35v kjdc1dyq kmwttqpk srn514ro oxkhqvkx rl78xhln nch0832m cr00lzj9 rn8ck1ys s3jn8y49 icdlwmnq jxuftiz4 cxfqmxzd tes86rjd')]")
  53. posts = driver.find_elements(By.XPATH, "//*[contains(@class,'qi72231t nu7423ey n3hqoq4p r86q59rh b3qcqh3k fq87ekyn bdao358l fsf7x5fv rse6dlih s5oniofx m8h3af8h l7ghb35v kjdc1dyq kmwttqpk srn514ro oxkhqvkx rl78xhln nch0832m cr00lzj9 rn8ck1ys s3jn8y49 icdlwmnq jxuftiz4 cxfqmxzd tes86rjd')]")
  54. print(len(reqs))
  55. print(len(authors))
  56. print(len(tags))
  57. print(output(reqs))
  58. print(output(authors))
  59. count = 0 #maximum posts liked at a time specified in ini
  60. #for req, author in zip(reqs, authors):
  61. for req in reqs:
  62. count += 1
  63. print("Post found")
  64. print(req.text)
  65. tsleep(15) #just in case you want to change your mind...
  66. webdriver.ActionChains(driver).move_to_element(req).perform()
  67. webdriver.ActionChains(driver).move_to_element(req).click().perform()
  68. #db['friend_requests'].insert({"datetime":datetime.now(), "name": lines[0], "page_link": url, "request_age": lines[1], "server_ID": serverid, "profile": selecteduser})
  69. print("Completed")
  70. if count == maxlikes:
  71. break
  72. if approval == 1:
  73. execute()