diff --git a/executable.py b/executable.py index 80cd435..822a23f 100644 --- a/executable.py +++ b/executable.py @@ -2,27 +2,29 @@ # Date: 02.05.2020 # Proper Executable +import sys from random import random from driver import getDriver from tinderlogin import TinderLogin from tinderbot import TinderBot from selenium.common.exceptions import NoSuchElementException -try: - driver = getDriver() - login = TinderLogin(driver) - bot = TinderBot(driver) +driver = getDriver() +login = TinderLogin(driver) +bot = TinderBot(driver) - login.logIn() - if login.isLogged(): - while True: - try: - bot.perform() - if bot.getTotalActions() % 10 == 0: - bot.show() - except NoSuchElementException: - print('Warning: Can\'t find element.') - else: - print('Error: Failed to login to Tinder. Check your data or try later.') -except: - print('Error: Something was missing. Report me: https://github.com/stanfortonski/Tinder-Bot') \ No newline at end of file +login.logIn() +if login.isLogged(): + print('=== Tinder Perform ===') + while True: + try: + bot.perform() + if bot.getTotalActions() % 10 == 0: + bot.show() + except NoSuchElementException as e: + print(f'Error: {e}\nReport me: https://github.com/stanfortonski/Tinder-Bot') + sys.exit() +else: + print('Error: Failed to login to Tinder. Check your data or try later.') + + \ No newline at end of file diff --git a/facebooklogin.py b/facebooklogin.py index d023841..5d35f05 100644 --- a/facebooklogin.py +++ b/facebooklogin.py @@ -4,6 +4,7 @@ from time import sleep from config import Config +from selenium.common.exceptions import NoSuchElementException class FacebookLogin: def __init__(self, driver): @@ -21,10 +22,10 @@ def logIn(self): driver.find_element_by_xpath('//*[@id="u_0_b"]').submit() sleep(6) try: - element = driver.find_element_by_partial_link_text('Log out') - self.__isLogged = False - except: + element = driver.find_element_by_css_selector('input[type="search"]') self.__isLogged = True + except NoSuchElementException: + self.__isLogged = False def isLogged(self): return self.__isLogged \ No newline at end of file diff --git a/tinderlogin.py b/tinderlogin.py index 56fc5d1..4ab798f 100644 --- a/tinderlogin.py +++ b/tinderlogin.py @@ -35,8 +35,6 @@ def logIn(self): self.__isLogged = 'tinder.com/app/recs' in driver.current_url if self.__isLogged: self.__closePopups() - driver.get('https://tinder.com/app/recs') - sleep(2) def __logInViaGoogle(self): driver = self.driver @@ -78,8 +76,14 @@ def __closePopups(self): sleep(2) driver.find_element_by_xpath('/html/body/div[2]/div/div/div/div/div[3]/button[1]').click() sleep(2) - driver.find_element_by_xpath('/html/body/div[2]/div/div/div[1]/a').click() - sleep(1) + try: + element = driver.find_element_by_xpath('/html/body/div[2]/div/div/div[1]/a') + element.click() + driver.get('https://tinder.com/app/recs') + sleep(2) + except NoSuchElementException: + pass + def isLogged(self): return self.__isLogged \ No newline at end of file