Use time correctly: process automation in Tinder


I think many people like to get acquainted in social. networks and use applications (for example Tinder),
but often it takes a lot of time to like and send first
messages. I believe that these are monotonous actions that only repel
communication and dating. If you are a programmer, why be like everyone else, let's
automate the process of monotonous actions with me and leave our attention only
for pleasant communication, but about everything in order.

Training


In this article, I will use the Chrome browser .
  1. Create a folder with the bot_tinder project .
  2. bot_tinder chromedriver_for_win chromedriver_for_mac, chromedriver_for_lin (.. 3 Windows, macOS, Linux).
  3. webdriver ( Chrome, Firefox ), .
  4. chromedriver_for_win, chromedriver_for_mac, chromedriver_for_lin.
    , , .. .
  5. In the bot_tinder folder , create a file called log.txt (we write down the phone number on which it will go to Tinder). Format without a figure eight: 9851234567
  6. In the bot_tinder folder , create the tinder.py , function.py files .

As a result, you should have the following:



Each folder should contain the webdriver file downloaded earlier.
If you implement it only for your OS, then the webdriver file should be located in only one of the folders with the name of your OS โ€œchromedriver_for_your OS โ€ .

Implementation


In the tinder.py file , import the library:

# -*- coding: utf-8-*-
from selenium import webdriver


In the function.py file, import the libraries:

from selenium.common.exceptions import NoSuchElementException, ElementNotInteractableException
from sys import platform
from time import sleep
import datetime

Next, in the function.py file, we create the variables that we will later need:

error = ''
warning = ''
ok = ''
oc = ''
like = ''
all_sleep = 3
like_sleep = 2
The icons were deleted by the Habr interpreter, but it should be like this:



You can copy the icons from the site or use the emoji library .
The variables all_sleep , like_sleep indicate the delay time in seconds.

After we create the functions in the function.py file :


  • The first function will determine the date and time:
    def get_data_time():
        time_now = datetime.datetime.now()
        return time_now.strftime("%d-%m-%Y %H:%M")

  • The second function will determine your OS and access the desired webdriver :

    def get_OC():
        """
        Define OS.
        :return: OS information and path to chromedriver.exe
        """
        if platform == "linux" or platform == "linux2":
            time_now = datetime.datetime.now()
            information = "[" + get_data_time() + '] {}   Linux'.format(oc)
            put = "chromedriver_for_lin/** webdriver**"
            return information, put
    
        elif platform == "darwin":
            time_now = datetime.datetime.now()
            information = "[" + get_data_time() + '] {}   Mac'.format(oc)
            put = "chromedriver_for_mac/** webdriver**"
            return information, put
    
        elif platform == "win32":
            time_now = datetime.datetime.now()
            information = "[" + get_data_time() + '] {}   Windows'.format(oc)
            put = "chromedriver_for_win/chromedriver.exe"
            return information, put

    Remember to write the path to webdriver in the put variable .

  • The third function will read the phone number from the log.txt file :

    def information_from_txt_files():
        """
        Read the .txt files
        :return: Information. Login.
        """
        information = ''
        with open('log.txt', 'r') as file:
            log = file.read()
            information += "[" + get_data_time() + \
                           '] {}      Tinder: {}'.format(ok, log) 
        return information, log

  • The fourth function will close the popup on the Tinder website:

    def close_start_popups(browser):
        """
        Close the popup.
        :param browser: parameter of the running browser.
        :return: information.
        """
        sleep(all_sleep)
        try:
            browser.find_element_by_xpath('//button[@aria-label=""]').click()
            return "[" + get_data_time() + "] {}   .".format(ok)
        except ElementNotInteractableException as err:
            return "[" + get_data_time() + '] {} ' + err + ''.format(error)
        except NoSuchElementException as err:
            return "[" + get_data_time() + '] {}    .'.format(error)

  • The fifth function will press the "Login using phone number" button :

    def log_in_using_your_phone(browser):
        """
        Click the Login button using the phone number.
        :param browser: parameter of the running browser.
        :return: information
        """
        sleep(all_sleep)
        try:
            browser.find_element_by_xpath('//div[@id="modal-manager"]').find_element_by_xpath('//button[@aria-label="    "]').click()
            return "[" + get_data_time() + "] {}     .".format(ok)
        except ElementNotInteractableException as err:
            return "[" + get_data_time() + '] {} ' + err + ''.format(error)
        except NoSuchElementException as err:
            browser.find_element_by_xpath('//button[text()=" "]').click()
            return log_in_using_your_phone(browser)

  • The sixth function will enter the phone number:

    def input_number_phone(browser, log):
        """
        Enter the phone number.
        :param browser: parameter of the running browser.
        :param log: phone number.
        :return: information.
        """
        sleep(all_sleep)
        try:
            browser.find_element_by_name('phone_number').send_keys(log)
            return "[" + get_data_time() + '] {}    {}'.format(ok, log)
        except NoSuchElementException:
            return "[" + get_data_time() + '] {}      .'.format(error)

  • The seventh function presses the Continue button :

    def go_on(browser):
        """
        Click the Continue button.
        :param browser: parameter of the running browser.
        :return: information
        """
        sleep(all_sleep)
        try:
            browser.find_element_by_xpath('//span[text()=""]').click()
            return "[" + get_data_time() + '] {}   '.format(ok)
        except NoSuchElementException:
            return "[" + get_data_time() + '] {}    .'.format(error)

  • The eighth function asks you to enter the code that will come to your phone:

    def code_check():
        """
        Entering a code and checking the entered code.
        :return: entered code
        """
        kod_numbers = input("[" + get_data_time() + "] {}  : ".format(warning))
        if len(kod_numbers) != 6:
            print("[" + get_data_time() + '] {}   .'.format(error))
            return code_check()
        else:
            print("[" + get_data_time() + '] {}   .'.format(ok))
            return kod_numbers

    The function also checks the number of entered digits.
  • The ninth function enters the code:

    def input_cod(browser):
        """
        Code entry.
        :param browser: parameter of the running browser.
        :return: information.
        """
        try:
            kod_numbers = code_check()
            kod = browser.find_elements_by_xpath('//input[@type="tel"]')
            n = 0
            for i in kod:
                i.send_keys(kod_numbers[n])
                n += 1
            return "[" + get_data_time() + '] {}  .'.format(ok)
        except NoSuchElementException:
            return "[" + get_data_time() + '] {}      .'.format(error)

  • The tenth function allows the definition of geolocation:

    def geolocation_ok(browser):
        """
        We allow geolocation.
        :param browser: parameter of the running browser.
        :return: information.
        """
        sleep(all_sleep)
        try:
            browser_button = browser.find_elements_by_tag_name("button")
            button_list = {i.text: i for i in browser_button}
            if "" in button_list.keys():
                button = [value for key, value in button_list.items() if key == ""]
                button[0].click()
                return "[" + get_data_time() + '] {}  .'.format(ok)
            else:
                return "[" + get_data_time() + '] {}      .'.format(error)
        except NoSuchElementException:
            return "[" + get_data_time() + '] {}      .'.format(error)

  • The eleventh function turns off the alert:

    def notice_off(browser):
        """
        Turn off notifications.
        :param browser: parameter of the running browser.
        :return: information.
        """
        sleep(all_sleep)
        try:
            browser_button = browser.find_elements_by_tag_name("button")
            button_list = {i.text: i for i in browser_button}
            if "" in button_list.keys():
                button = [value for key, value in button_list.items() if key == ""]
                button[0].click()
                return "[" + get_data_time() + '] {}  .'.format(ok)
            else:
                return "[" + get_data_time() + '] {}      .'.format(error)
        except NoSuchElementException:
            return "[" + get_data_time() + '] {}      .'.format(error)

  • The twelfth function closes pop-ups:

    def popup_windows_off(browser):
        """
        Close popups.
        :param browser: parameter of the running browser
        :return: information
        """
        sleep(like_sleep)
        try:
            browser_button = browser.find_elements_by_tag_name("button")
            button_list = {i.text: i for i in browser_button}
            if "" in button_list.keys():
                button = [value for key, value in button_list.items() if key == ""]
                button[0].click()
                print("[" + get_data_time() + '] {}  .'.format(ok))
        except NoSuchElementException:
            pass

  • The thirteenth function puts Like:

    def click_like(browser):
        """
        Click LIKE.
        :param browser: parameter of the running browser
        :return: information
        """
        sum_like = 0
        while True:
            try:
                popup_windows_off(browser)
                browser.find_element_by_xpath('//button[@aria-label=""]').click()
                sum_like += 1
                print("[" + get_data_time() + '] {} - {}'.format(like, str(sum_like)))
            except NoSuchElementException:
                print("[" + get_data_time() + '] {}    .'.format(error))


Now go to the tinder.py file and register the import of all functions:

from function import get_OC, information_from_txt_files, close_start_popups, notice_off, click_like, log_in_using_your_phone, input_number_phone, go_on, input_cod, geolocation_ok

Define the OS:
#  
info, put = get_OC()
print(info)

Set browser options:

#    chrome
chromedriver = put
options = webdriver.ChromeOptions()
options.add_argument('--start-minimize')
browser = webdriver.Chrome(executable_path=chromedriver, chrome_options=options)

If you work with Firefox then read how to work with it using the selenium.webdriver library .

The browser launches and goes to the Tinder page:

#        
browser.get('https://tinder.com/app/recs')

Now we begin to use the functions prepared earlier:

#  txt   
info_txt, log = information_from_txt_files()
print(info_txt)
#     
print(close_start_popups(browser))
#     
print(log_in_using_your_phone(browser))
#   
print(input_number_phone(browser, log))
#   
print(go_on(browser))
#  
print(input_cod(browser))
#   
print(go_on(browser))
#     
print(geolocation_ok(browser))
#   
print(notice_off(browser))
#  
click_like(browser)

Conclusion


In the end, get a bot that goes to the Tinder website and clicks on Like.

You just have to go into the application in a couple of hours and start talking with already mutual
sympathies.
Automation is the effort of men to simplify work so that women can do it.
In the next article, we will implement the ability to send messages for mutual likes.

All Articles