Efficient net pick-up learned with Python

Overview

For those who want her but don't have the time, I would like to automate + alpha the free and easy-to-use matching app tinder.

Preparation

・ Facebook account ・ Tinder account Please use facebook for automation of tinder registration. If you have any problems, we recommend that you create a new account to prevent your body from getting caught (laughs).

Obtaining an access token

You must get an access token to log in to tinder using the api. Please note that the method of obtaining an access token will change immediately due to changes in the specifications of the site, so there is a possibility that the method you can do now will not be possible. I'm pretty stuck here. First, put in the library to get the tinder-token. (Reference: https://pypi.org/project/tinder-token/)

pip install tinder-token

Once in, try creating and running the following program. If you don't have the required library, please add it as appropriate.

get_token.py


from tinder_token.facebook import TinderTokenFacebookV2
mail = "Email address for facebook login"
password = "facebook password"
facebook = TinderTokenFacebookV2()
def sample_email_password(email: str, password: str) -> (str, str):
    return facebook.get_tinder_token(fb_email=email, fb_password=password)

api_token = sample_email_password(mail,password)[0]
print(api_token)

If you execute this and a long character string is displayed, the acquisition is successful.

Log in to tinder

Now that you have the api code with the code above, you can finally log in.

import requests
s = requests.Session()

#Log in to Tinder
headers = {"X-Auth-Token": api_token, "Content-type": "application/json",
           "User-agent": "Tinder/10.1.0 (iPhone; iOS 12.1; Scale/2.00)"}
s.headers.update(headers)
meta = s.get("https://api.gotinder.com/meta")
print(meta.text)

Put the api token you got earlier in the variable api_token. It is easier to connect the cords, so we recommend connecting them. It's okay if your information comes out in a row.

Get user

You can collect user information near your favorite points by passing latitude / longitude information in post. Various information such as the user's name and ID photo are stored in the user variable. Since this program gets the name, the name should be output in a smooth manner.

url = "https://api.gotinder.com/" + endpoint
latitude = "latitude"
longitude = "longitude"
params = {"lat": latitude, "lon": longitude}
response = s.post(url, data=json.dumps(params))
limit = 10
params = {"limit": limit}
for i in range(3):
    users = s.post("https://api.gotinder.com/user/recs", data=json.dumps(params))
    content = users.content
    if len(content) > 0:
        content = content.decode("utf-8")
        content = json.loads(content)
    else:
        break
        #print(content)
    
    for user in content["results"]:
        #print(user)
        print(user["name"])

Fully automatic like

It is possible to like any id by hitting / like / {id} with get.

url = "https://api.gotinder.com/" + endpoint
latitude = "latitude"
longitude = "longitude"
params = {"lat": latitude, "lon": longitude}
response = s.post(url, data=json.dumps(params))
limit = 10
params = {"limit": limit}
for i in range(3):
    users = s.post("https://api.gotinder.com/user/recs", data=json.dumps(params))
    content = users.content
    if len(content) > 0:
        content = content.decode("utf-8")
        content = json.loads(content)
    else:
        break
        #print(content)
    
    for user in content["results"]:
        #print(user)
        print(user["name"])

        id = user["_id"]
        #Swipe right
        s.get("https://api.gotinder.com/like/{}".format(id))

For those who are not interested in the power skills that everyone is like

It's true that the number of encounters is important, but I thought of an option for those who still want quality. Do you know the Face ++ API? FaceAPI was developed by a Chinese company and is a terrifying API that scores the beauty of the face, the so-called facial deviation value. The great thing about this API is that it can be used for free.

face ++ registration

Register from the following URL. https://console.faceplusplus.com/register After logging in, look at the API Key page and make a note of the API Key and API secret. image.png

Score your face with face ++

It is made into a class considering cooperation with tinder. Place the photo you want to judge in the same directory as the program, and set test.jpeg to the file name of the image you want to judge, and the score will be output. By the way, Mr. Shin 〇〇 was 88.74 points. It's a really high score. I think it's a good idea to try some of them yourself and see the market view.

faceplus


import requests
import base64

class FacePlus:
    def __init__(self,key,secret):
        self.key = key
        self.secret = secret
        self.endpoint = 'https://api-us.faceplusplus.com'
        
    def judge_face(self,path):
        img_file = base64.encodestring(open(path, 'rb').read())
        response = requests.post(
            self.endpoint + '/facepp/v3/detect',
            {
        'Content-Type': 'multipart/form-data',
        'api_key': self.key,
        'api_secret': self.secret,
        'image_base64': img_file,
        'return_attributes': 'gender,age,headpose,facequality,eyestatus,emotion,ethnicity,beauty,mouthstatus'
        }
        )
        result = response.json()
        return result["faces"][0]["attributes"]["beauty"]["female_score"]
if __name__ == '__main__':
    key = "API token"
    secret = "API secret"
       
    fp = FacePlus(key, secret)  
    print(fp.judge_face("test.jpeg ")) 

#Works with tinder's auto-like Notes ・ For those who have multiple photos, refer to the first one. -It is necessary to create a tmp folder, and the photo data will be saved in the tmp folder. -Adjust the like threshold by changing the score of the if statement of score. ・ Try,Use the except sentence to repel photos that do not have a face photo.

import requests
import json
import os
from tinder_token.facebook import TinderTokenFacebookV2
import urllib.error
import urllib.request
import faceplus
facebook = TinderTokenFacebookV2()
key = "face++_api"
secret = "face++_api_secret"

mail = "facebook_mail"
password = "facebook_password"

border = 75
fp = faceplus.FacePlus(key,secret)

def sample_email_password(email: str, password: str) -> (str, str):
    return facebook.get_tinder_token(fb_email=email, fb_password=password)



def download_file(url, dst_path):
    try:
        with urllib.request.urlopen(url) as web_file:
            data = web_file.read()
            with open(dst_path, mode='wb') as local_file:
                local_file.write(data)
    except urllib.error.URLError as e:
        print(e)
def download_file_to_dir(url, dst_dir):
    download_file(url, os.path.join(dst_dir, os.path.basename(url)))


# Get Tinder Token

api_token = sample_email_password(mail,password)[0]


s = requests.Session()
# Log in to Tinder
headers = {"X-Auth-Token": api_token, "Content-type": "application/json",
           "User-agent": "Tinder/10.1.0 (iPhone; iOS 12.1; Scale/2.00)"}
s.headers.update(headers)
meta = s.get("https://api.gotinder.com/meta")
print(meta.text)

endpoint = "v2/meta"
# Latitude and longitude of Shibuya
latitude = 35.658034
longitude = 139.701636
params = {"lat": latitude, "lon": longitude}
url = "https://api.gotinder.com/" + endpoint
response = s.post(url, data=json.dumps(params))


limit = 10
params = {"limit": limit}
name_list = []

for i in range(3):
    users=s.post("https://api.gotinder.com/user/recs", data=json.dumps(params))
    content = users.content
    if len(content) > 0:
        content = content.decode("utf-8")
        content = json.loads(content)
    else:
        break
    #print(content)

    for user in content["results"]:
        #print(user)
        print(user["name"])
        id = user["_id"]

        name_list.append(user["name"])
        
        photo = user['photos'][0]

 Create a #tmp file
        dst_dir = 'tmp/'
        print(photo['url'])
 #Save file
        download_file_to_dir(photo['url'], dst_dir)
            
        f_name = photo['url'].split('/')[-1]
        print(f_name)
        try:
            score = fp.judge_face("./tmp/"+f_name)
            print(score)
            if(score >= border):
 #Right swipe
                s.get("https://api.gotinder.com/like/{}".format(id))
        except:
            print("error")

#Summary Although it was good to make, I was satisfied when it was completed and I couldn't do the demonstration experiment after all. It's a bad thing about engineers whose purpose changes on the way.(Lol)。

Follow the rules and have a fun tinder life!

#References

[1]https://qiita.com/Fulltea/items/fe4d4214552476c28e88 [2]https://note.com/ryohei55/n/n72084219f751

Recommended Posts

Efficient net pick-up learned with Python
Python data structures learned with chemoinformatics
1. Statistics learned with Python 1-1. Basic statistics (Pandas)
[Python] Reactive Extensions learned with RxPY (3.0.1) [Rx]
Algorithm learned with Python 10th: Binary search
Algorithm learned with Python 5th: Fibonacci sequence
Algorithm learned with Python 9th: Linear search
Algorithm learned with Python 7th: Year conversion
Algorithm learned with Python 8th: Evaluation of algorithm
Algorithm learned with Python 2nd: Vending machine
Algorithm learned with Python 6th: Leap year
1. Statistics learned with Python 1-3. Calculation of various statistics (statistics)
Algorithm learned with Python 3rd: Radix conversion
Algorithm learned with Python 12th: Maze search
Algorithm learned with Python 11th: Tree structure
FizzBuzz with Python3
Scraping with Python
Statistics with python
Scraping with Python
Python with Go
Twilio with Python
Integrate with Python
Play with 2016-Python
AES256 with python
Tested with Python
python starts with ()
with syntax (Python)
Bingo with python
Zundokokiyoshi with python
Excel with Python
Microcomputer with Python
Cast with python
Algorithm learned with Python 13th: Tower of Hanoi
Algorithm learned with Python 16th: Sorting (insertion sort)
Algorithm learned with Python 14th: Tic-tac-toe (ox problem)
Algorithm learned with Python 15th: Sorting (selection sort)
1. Statistics learned with Python 1-2. Calculation of various statistics (Numpy)
Algorithm learned with Python 17th: Sorting (bubble sort)
Use Python and word2vec (learned) with Azure Databricks
1. Statistics learned with Python 2-1. Probability distribution [discrete variable]
"Principle of dependency reversal" learned slowly with Python
Serial communication with Python
Zip, unzip with python
Django 1.11 started with Python3.6
Primality test with Python
Python with eclipse + PyDev.
Socket communication with Python
Data analysis with python 2
Scraping with Python (preparation)
I learned Python with a beautiful girl at Paiza # 02
Learning Python with ChemTHEATER 03
Sequential search with Python
Run Python with VBA
Handling yaml with python
Solve AtCoder 167 with python
Serial communication with python
[Python] Use JSON with Python
Learning Python with ChemTHEATER 05-1
Learn Python with ChemTHEATER
Run prepDE.py with python3
1.1 Getting Started with Python