Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code restructure; PEP8 standards; readability #45

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 41 additions & 27 deletions bdaybot/chrome.py
Original file line number Diff line number Diff line change
@@ -1,58 +1,72 @@
from selenium import webdriver
import time
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

from selenium import webdriver
from selenium.common.exceptions import TimeoutException
from selenium.webdriver.common.by import By
from selenium.common.exceptions import NoSuchElementException


from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait

driver = webdriver.Chrome()
driver.get("http://www.facebook.com")
assert "Facebook" in driver.title
elem = driver.find_element_by_name("email")
elem.clear()

elem.send_keys("[email protected]")
elem = driver.find_element_by_name("pass")
elem.clear()

elem.send_keys("12345679")
elem.send_keys(Keys.RETURN)

delay = 30


def post_checker(post):
happy_word_list = ['happy', 'hapy', 'hapi', 'appy', 'hpy']
birthday_word_list = ['birthday', 'bday', 'budday', 'b\'day', 'bdy']
return any(word in post for word in happy_word_list) and (any(word in post for word in birthday_word_list) or
('return' in post and 'day' in post))

try:
elem=WebDriverWait(driver,delay).until(EC.presence_of_element_located((By.CLASS_NAME,"_2s25")))
time.sleep(5);
elem.click();
print ("Successfully Logged in")
elem = WebDriverWait(driver, delay).until(EC.presence_of_element_located((By.CLASS_NAME, "_2s25")))
time.sleep(5)
elem.click()
print("Successfully Logged in")

except TimeoutException:
print ("Timeout or wrong email/password")
driver.close();
print("Timeout or wrong email/password")
driver.close()

posts = []

def post_checker(post):
hpylst = ['happy','hapy','hapi','appy','hpy']
bdylst = ['birthday','bday','budday','b\'day','bdy']
return any(word in post for word in hpylst) and (any(word in post for word in bdylst) or ('return' in post and 'day' in post))
posts=[]
try:
elem=WebDriverWait(driver,delay).until(EC.presence_of_element_located((By.CLASS_NAME,"_44b2")))
time.sleep(5);
elem.click();
posts=WebDriverWait(driver,delay).until(EC.presence_of_element_located((By.CLASS_NAME,'userContentWrapper')))
elem = WebDriverWait(driver, delay).until(EC.presence_of_element_located((By.CLASS_NAME, "_44b2")))
time.sleep(5)
elem.click()
posts = WebDriverWait(driver, delay).until(EC.presence_of_element_located((By.CLASS_NAME, 'userContentWrapper')))
time.sleep(8)
posts=driver.find_elements_by_class_name('userContentWrapper')
posts = driver.find_elements_by_class_name('userContentWrapper')

for post in posts:
post_text=post.find_element_by_xpath(".//div[@class='_5pbx userContent']").text.lower()

post_text = post.find_element_by_xpath(".//div[@class='_5pbx userContent']").text.lower()

time.sleep(3)

if post_checker(post_text):

try:
post.find_element_by_xpath(".//a[@class='UFILikeLink _4x9- _4x9_ _48-k']").click()

except:
continue
print ("Successfully liked relevant posts")
pass

print("Successfully liked relevant posts")

except TimeoutException:
print ("Timeout")
print("Timeout")

app_secret = 'a508a47755cb78460fde5c52c9b9230f'
app_id = '1178068725594212'
Loading