Utiliser le temps correctement: automatisation des processus dans Tinder


Je pense que beaucoup de gens aiment se familiariser avec le social. réseaux et utiliser des applications (par exemple Tinder),
mais il faut souvent beaucoup de temps pour aimer et envoyer les premiers
messages. Je pense que ce sont des actions monotones qui ne font que repousser la
communication et les rencontres. Si vous êtes programmeur, pourquoi être comme tout le monde,
automatisons avec moi le processus des actions monotones et ne laissons notre attention que
pour une communication agréable, mais sur tout dans l'ordre.

Entraînement


Dans cet article, j'utiliserai le navigateur Chrome .
  1. Créez un dossier avec le projet 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. Dans le dossier bot_tinder, créez un fichier appelé log.txt (nous écrivons le numéro de téléphone sur lequel il ira à Tinder). Format sans chiffre huit: 9851234567
  6. Dans le dossier bot_tinder, créez les fichiers tinder.py , function.py .

Par conséquent, vous devez disposer des éléments suivants:



Chaque dossier doit contenir le fichier du pilote Web téléchargé précédemment.
Si vous l'implémentez uniquement pour votre système d'exploitation, le fichier du pilote Web doit se trouver dans un seul des dossiers portant le nom de votre système d'exploitation "chromedriver_for_your OS " .

la mise en oeuvre


Dans le fichier tinder.py, importez la bibliothèque:

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


Dans le fichier function.py , importez les bibliothèques:

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

Ensuite, dans le fichier function.py , nous créons les variables dont nous aurons besoin plus tard:

error = ''
warning = ''
ok = ''
oc = ''
like = ''
all_sleep = 3
like_sleep = 2
Les icônes ont été supprimées par l'interpréteur Habr, mais cela devrait ressembler à ceci:



vous pouvez copier les icônes du site ou utiliser la bibliothèque d' emoji .
Les variables all_sleep , like_sleep indiquent le temps de retard en secondes.

Après avoir créé les fonctions dans le fichier function.py :


  • La première fonction déterminera la date et l'heure:
    def get_data_time():
        time_now = datetime.datetime.now()
        return time_now.strftime("%d-%m-%Y %H:%M")

  • La deuxième fonction déterminera votre système d'exploitation et accédera au pilote Web souhaité :

    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

    N'oubliez pas d'écrire le chemin vers le pilote Web dans la variable put .

  • La troisième fonction lira le numéro de téléphone du fichier 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 quatrième fonction fermera la fenêtre contextuelle sur le site 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 cinquième fonction va appuyer sur le bouton "Se connecter en utilisant le numéro de téléphone" :

    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 sixième fonction entrera le numéro de téléphone:

    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 septième fonction appuie sur le bouton Continuer :

    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 huitième fonction vous demande d'entrer le code qui viendra sur votre télé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

    La fonction vérifie également le nombre de chiffres saisis.
  • La neuvième fonction entre le 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)

  • La dixième fonction permet de définir la géolocalisation:

    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 onzième fonction désactive l'alerte:

    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 douzième fonction ferme les fenêtres contextuelles:

    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 treizième fonction met 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))


Accédez maintenant au fichier tinder.py et enregistrez l'importation de toutes les fonctions:

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

Définissez le système d'exploitation:
#  
info, put = get_OC()
print(info)

Définissez les options du navigateur:

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

Si vous travaillez avec Firefox, lisez comment l'utiliser avec la bibliothèque selenium.webdriver .

Le navigateur se lance et accède à la page Tinder:

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

Nous commençons maintenant à utiliser les fonctions préparées précédemment:

#  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


À la fin, obtenez un bot qui va sur le site Web de Tinder et clique sur J'aime.

Il vous suffit d'entrer dans l'application en quelques heures et de commencer à parler avec des
sympathies déjà mutuelles .
L'automatisation est l'effort des hommes pour simplifier le travail afin que les femmes puissent le faire.
Dans le prochain article, nous mettrons en œuvre la possibilité d'envoyer des messages pour des goûts mutuels.

All Articles