From f6b796ee9f01a949e103233213988f41d773b8fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stan=20Forto=C5=84ski?= Date: Sat, 9 Oct 2021 13:36:26 +0200 Subject: [PATCH] Improved stability --- README.md | 3 +-- app-finder.py | 7 +++---- app.py | 22 +++++----------------- config.json | 5 ++--- driver.py | 6 +++--- tests/config.json | 7 +++---- tests/instagramfinder_test.py | 2 +- tests/snapchatfinder_test.py | 2 +- tinder/tinderbot.py | 26 +++++++++++++++----------- 9 files changed, 34 insertions(+), 46 deletions(-) diff --git a/README.md b/README.md index bfa039d..314ae7f 100644 --- a/README.md +++ b/README.md @@ -41,9 +41,8 @@ In your `config.json` file have to change following things: - If `chance_to_like` is 100 It will give only likes. - Default is 90. 4. To set wait time between give next like or dislike you have to change `max_wait_time_between_action_in_sec` for maximal time delay and -`min_wait_time_between_action_in_sec` for minimal time delay. Default `max_wait_time_between_action_in_sec` is 10 and `min_wait_time_between_action_in_sec` is 4. +`min_wait_time_between_action_in_sec` for minimal time delay. Default `min_wait_time_between_action_in_sec` is 2 and `max_wait_time_between_action_in_sec` is 5. 5. This option `amount_of_login_attempts` sets the number of attempts after which if you don't log in It will error occurs. Default is 15. -6. This option `amount_of_avoid_errors` sets the number of attempts that after program will show error message and exit. Default is 5. 7. If you want to save Instagram nick from description set `allow_to_save_ig` to true. Default is true. 8. Choose path to your file with Instagram nicknames so change `ig_file_path`. Default is "logs/instagram.txt". 9. If you want to save Snapchat nick from description set `allow_to_save_snap` to True. Default is true. diff --git a/app-finder.py b/app-finder.py index c05cd38..51c8950 100644 --- a/app-finder.py +++ b/app-finder.py @@ -14,7 +14,7 @@ igFinder = InstagramFinder(driver) snapFinder = SnapchatFinder(driver) -print('=== Tinder Finder Only Start ===') +print('=== Tinder Finder ===') login.logIn() if login.isLogged(): print('=== Instagram/Snapchat Finding ===') @@ -27,8 +27,7 @@ if igFinder.getTotalSaves() != 0 and igFinder.getTotalSaves() % 10 == 0: print(igFinder, snapFinder) fn.waitRandomTime() - except NoSuchElementException as e: - print(f'Error: {e}\nReport me: https://github.com/stanfortonski/Tinder-Bot') - break + except: + fn.waitRandomTime() else: print('Error: Failed to login to Tinder. Check your data or try later.') \ No newline at end of file diff --git a/app.py b/app.py index ac8484e..79b4e46 100644 --- a/app.py +++ b/app.py @@ -10,34 +10,22 @@ from tinder.finder.snapchatfinder import SnapchatFinder from selenium.common.exceptions import NoSuchElementException from tinder.config import Config -from time import sleep driver = getDriver() login = TinderLogin(driver) bot = TinderBot(driver) igFinder = InstagramFinder(driver) snapFinder = SnapchatFinder(driver) -errors = 0 print('=== TinderBot Start ===') login.logIn() if login.isLogged(): print('=== Tinder Perform ===') while True: - try: - bot.perform() - igFinder.findAndSaveInstagramNick() - snapFinder.findAndSaveSnapchatNick() - if bot.getTotalActions() % 10 == 0: - print(bot, igFinder, snapFinder) - errors = 0 - except NoSuchElementException as e: - errors += 1 - if errors >= Config['amount_of_avoid_errors']: - print(f'Error: {e}\nReport me: https://github.com/stanfortonski/Tinder-Bot') - break - else: - driver.get('https://tinder.com/app/recs') - sleep(5) + bot.perform() + igFinder.findAndSaveInstagramNick() + snapFinder.findAndSaveSnapchatNick() + if bot.getTotalActions() % 10 == 0: + print(bot, igFinder, snapFinder) else: print('Error: Failed to login to Tinder. Check your data or try later.') \ No newline at end of file diff --git a/config.json b/config.json index d2f8716..7b14928 100644 --- a/config.json +++ b/config.json @@ -10,9 +10,8 @@ "login_method": "facebook", "chance_to_like": 90, "amount_of_login_attempts": 15, - "amount_of_avoid_errors": 5, - "max_wait_time_between_action_in_sec": 10, - "min_wait_time_between_action_in_sec": 4, + "max_wait_time_between_action_in_sec": 5, + "min_wait_time_between_action_in_sec": 2, "allow_to_save_ig": true, "ig_file_path": "logs/instagram.txt", "allow_to_save_snap": true, diff --git a/driver.py b/driver.py index ae889c9..3c4df2a 100644 --- a/driver.py +++ b/driver.py @@ -7,7 +7,7 @@ def getDriver(): geoEnable = webdriver.FirefoxOptions() geoEnable.set_preference('geo.enabled', True) - geoEnable.set_preference('geo.provider.use_corelocation', True); - geoEnable.set_preference('geo.prompt.testing', True); - geoEnable.set_preference('geo.prompt.testing.allow', True); + geoEnable.set_preference('geo.provider.use_corelocation', True) + geoEnable.set_preference('geo.prompt.testing', True) + geoEnable.set_preference('geo.prompt.testing.allow', True) return webdriver.Firefox(options=geoEnable) \ No newline at end of file diff --git a/tests/config.json b/tests/config.json index 88f0b85..7b14928 100644 --- a/tests/config.json +++ b/tests/config.json @@ -10,11 +10,10 @@ "login_method": "facebook", "chance_to_like": 90, "amount_of_login_attempts": 15, - "amount_of_avoid_errors": 5, "max_wait_time_between_action_in_sec": 5, - "min_wait_time_between_action_in_sec": 4, + "min_wait_time_between_action_in_sec": 2, "allow_to_save_ig": true, - "ig_file_path": "instagram.txt", + "ig_file_path": "logs/instagram.txt", "allow_to_save_snap": true, - "snap_file_path": "snap.txt" + "snap_file_path": "logs/snap.txt" } \ No newline at end of file diff --git a/tests/instagramfinder_test.py b/tests/instagramfinder_test.py index 562cdc9..2102bad 100644 --- a/tests/instagramfinder_test.py +++ b/tests/instagramfinder_test.py @@ -28,7 +28,7 @@ def setUp(self): def changeNameScript(self, name): while True: try: - self.driver.execute_script('document.querySelector("#content > div > div:nth-child(1) > div > main > div:nth-child(1) > div > div > div:nth-child(1) > div > div:nth-child(1) > div:nth-child(3) > div:nth-child(6) > div > div:nth-child(2) > div > div > span").innerHTML = "'+name+'"'); + self.driver.execute_script('document.querySelector("#content > div > div:nth-child(1) > div > main > div:nth-child(1) > div > div > div:nth-child(1) > div > div:nth-child(1) > div:nth-child(3) > div:nth-child(6) > div > div:nth-child(2) > div > div > span").innerHTML = "'+name+'"') break except: self.driver.get('https://tinder.com/app/recs') diff --git a/tests/snapchatfinder_test.py b/tests/snapchatfinder_test.py index 3b78690..61da3e2 100644 --- a/tests/snapchatfinder_test.py +++ b/tests/snapchatfinder_test.py @@ -28,7 +28,7 @@ def setUp(self): def changeNameScript(self, name): while True: try: - self.driver.execute_script('document.querySelector("#content > div > div:nth-child(1) > div > main > div:nth-child(1) > div > div > div:nth-child(1) > div > div:nth-child(1) > div:nth-child(3) > div:nth-child(6) > div > div:nth-child(2) > div > div > span").innerHTML = "'+name+'"'); + self.driver.execute_script('document.querySelector("#content > div > div:nth-child(1) > div > main > div:nth-child(1) > div > div > div:nth-child(1) > div > div:nth-child(1) > div:nth-child(3) > div:nth-child(6) > div > div:nth-child(2) > div > div > span").innerHTML = "'+name+'"') break except: self.driver.get('https://tinder.com/app/recs') diff --git a/tinder/tinderbot.py b/tinder/tinderbot.py index 50bc537..b40e49f 100644 --- a/tinder/tinderbot.py +++ b/tinder/tinderbot.py @@ -18,14 +18,18 @@ def __init__(self, driver): def perform(self, wait=True): if 'app/recs' in self.driver.current_url: - self.__doOutOfLikesPopup() - fn.waitForPeople(self.driver) - chanceToLike = randrange(1, 100) - if chanceToLike <= Config['chance_to_like']: - self.like() - else: - self.dislike() - if wait: + try: + self.__doOutOfLikesPopup() + fn.waitForPeople(self.driver) + chanceToLike = randrange(1, 100) + if chanceToLike <= Config['chance_to_like']: + self.like() + else: + self.dislike() + if wait: + fn.waitRandomTime() + except: + self.driver.get('https://tinder.com/app/recs') fn.waitRandomTime() def __doOutOfLikesPopup(self): @@ -72,17 +76,17 @@ def dislike(self): def solveProblems(self): try: self.driver.find_element_by_xpath('/html/body/div[2]/div/div/div/div[3]/button[2]').click() - except NoSuchElementException: + except (ElementClickInterceptedException, NoSuchElementException): pass try: self.driver.find_element_by_xpath('/html/body/div[2]/div/div/button[2]').click() - except NoSuchElementException: + except (ElementClickInterceptedException, NoSuchElementException): pass try: self.driver.find_element_by_xpath('/html/body/div[1]/div/div[1]/div/main/div[2]/div/div/div[1]/div/div[4]/button').click() - except NoSuchElementException: + except (ElementClickInterceptedException, NoSuchElementException): pass def __str__(self):