Create Tinder Bot with Python
Tags: python, tinder, bot
Published: 2020-02-22 13:43:09

Watched this youtube video.

{% youtube lvFAuUcowT4 %}


The code is based on the video. I added a couple of things to it.


### 1. Allow a user to input username/password instead of using python file

`tinder_bot.py`
```python
# input email/username
email_input = self.driver.find_element_by_xpath('//*[@id="email"]')
username = getpass.getpass('please input username\n')
email_input.send_keys(username)

# input password
password_input = self.driver.find_element_by_xpath('//*[@id="pass"]')
password = getpass.getpass('please input password\n')
password_input.send_keys(password)
```

### 2. Support 2FA
Can pass the boolean to enable input and click function for 2FA

`app.py`
```python
two_fa = True # if don't need 2FA just pass False
bot.login(two_fa)
```

### 3. Swipe randomly
The video does swipe right simply. I just make that a little bit fun lol

`tinder_bot.py`
```python
if rand > 0.5:
    try:
        if debug:
            print('swipe like')
        self.like()
    except Exception:
        try:
            self.close_popup()
        except Exception:
            self.close_match()
else:
    if debug:
        print('swipe not like')
    self.not_like()
```

### 4. Display action
As you can see, I added `debug` to show action in the Terminal.

`app.py`
```python
debug = True # if pass False, prints don't show up
bot.auto_swipe(debug)
```

### 5. Screenshot
If the script swipe right, it will take a screenshot and give a random string to a png file. 

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/g601m1g79hggkrr3a7ag.png)

1. Get image url from the element (css background-image)
2. Get a `webp` and convert it
3. Save no.2 as a `png`

`tinder_bot.py`
```python
def take_screenshot(self):
      filename = self.randomString()+'.png'
      image = self.driver.find_element_by_xpath(
          '//*[@id="content"]/div/div[1]/div/main/div[1]/div/div/div[1]/div/div[1]/div[3]/div[1]/div[1]/div/div[1]/div/div')
      image_url = image.value_of_css_property("background-image")
      raw_url = image_url.replace('url("', '').replace('")', '')
      # get webp
      # convert webp --> png
      resp = requests.get(raw_url)
      im = Image.open(BytesIO(resp.content)).convert("RGB")
      im.save(filename, "png")
```

~~From an image, we could get a couple of things like `name`, `age`, `one-line profile` and `Instagram username` with `pytesseract` (OCR package)~~
This is not necessary since we can get them from the website directly lol

### 6. Terminate
As you may know, Tinder's biz model is a subscription model, so if you don't pay, Tinder will show you a popup that recommends you to purchase a subscription. This script is for fun and I don't use Tinder, so I need to terminate a program instead of aborting by an error.

`tinder_bot.py`
```python
def not_pay(self):
    popup = self.driver.find_element_by_xpath(
          '//*[@id="modal-manager"]/div/div/div[3]/button[2]')
    popup.click()
    print('cannot swipe any more')
    print('will finish the program')
```

If you have a Facebook account and Tinder account, you can try this simple Tinder bot.

{%  github koji/tinder-bot %}


Maybe you are interested in doing something with `javascript` instead of using python.
{% link https://dev.to/kojikanao/super-useless-snippets-for-tinder-k4e %}

Icons made by <a href="https://www.flaticon.com/authors/freepik" title="Freepik">Freepik</a> from <a href="https://www.flaticon.com/" title="Flaticon"> www.flaticon.com</a>