Usar el tiempo correctamente: automatización de procesos en Tinder


Creo que a muchas personas les gusta familiarizarse con las redes sociales. redes y aplicaciones de uso (por ejemplo, Tinder),
pero a menudo lleva mucho tiempo dar me gusta y enviar los primeros
mensajes. Creo que estas son acciones monótonas que solo repelen la
comunicación y las citas. Si usted es un programador, ¿por qué ser como todos los demás?
Automaticemos el proceso de acciones monótonas conmigo y dejemos nuestra atención solo
para una comunicación agradable, pero sobre todo en orden.

Formación


En este artículo, usaré el navegador Chrome .
  1. Crea una carpeta con el proyecto bot_tinder .
  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. En la carpeta bot_tinder, cree un archivo llamado log.txt ( anotamos el número de teléfono en el que irá a Tinder). Formato sin figura ocho: 9851234567
  6. En la carpeta bot_tinder, cree los archivos tinder.py , function.py .

Como resultado, debe tener lo siguiente:



Cada carpeta debe contener el archivo de controlador web descargado anteriormente.
Si lo implementa solo para su sistema operativo, el archivo del controlador web debe ubicarse en una sola de las carpetas con el nombre de su sistema operativo "chromedriver_for_your OS " .

Implementación


En el archivo tinder.py, importe la biblioteca:

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


En el archivo function.py , importe las bibliotecas:

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

A continuación, en el archivo function.py , creamos las variables que luego necesitaremos:

error = ''
warning = ''
ok = ''
oc = ''
like = ''
all_sleep = 3
like_sleep = 2
El intérprete Habr eliminó los íconos, pero debería ser así:



puede copiar los íconos del sitio o usar la biblioteca de emojis .
Las variables all_sleep , like_sleep indican el tiempo de retraso en segundos.

Después de crear las funciones en el archivo function.py :


  • La primera función determinará la fecha y la hora:
    def get_data_time():
        time_now = datetime.datetime.now()
        return time_now.strftime("%d-%m-%Y %H:%M")

  • La segunda función determinará su sistema operativo y accederá al controlador web deseado :

    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

    Recuerde escribir la ruta al controlador web en la variable put .

  • La tercera función leerá el número de teléfono del archivo log.txt :

    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

  • La cuarta función cerrará la ventana emergente en el sitio web de Tinder:

    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)

  • La quinta función presionará el botón "Iniciar sesión con el número de teléfono" :

    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)

  • La sexta función ingresará el número de teléfono:

    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)

  • La séptima función presiona el botón Continuar :

    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)

  • La octava función le pide que ingrese el código que llegará a su teléfono:

    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

    La función también verifica el número de dígitos ingresados.
  • La novena función ingresa el código:

    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)

  • La décima función permite la definición de geolocalización:

    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)

  • La undécima función apaga la alerta:

    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)

  • La duodécima función cierra las ventanas emergentes:

    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

  • La decimotercera función pone Me gusta:

    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))


Ahora vaya al archivo tinder.py y registre la importación de todas las funciones:

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

Definir el sistema operativo:
#  
info, put = get_OC()
print(info)

Establecer las opciones del navegador:

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

Si trabaja con Firefox , lea cómo hacerlo con la biblioteca selenium.webdriver .

El navegador se inicia y va a la página de Tinder:

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

Ahora comenzamos a usar las funciones preparadas anteriormente:

#  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)

Conclusión


Al final, obtenga un bot que vaya al sitio web de Tinder y haga clic en Me gusta.

Solo tiene que ingresar a la aplicación en un par de horas y comenzar a hablar con
simpatías ya mutuas .
La automatización es el esfuerzo de los hombres por simplificar el trabajo para que las mujeres puedan hacerlo.
En el próximo artículo, implementaremos la capacidad de enviar mensajes para gustos mutuos.

All Articles