File size: 2,526 Bytes
2f50f00
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
094b3bd
 
 
 
 
2f50f00
094b3bd
2f50f00
 
094b3bd
2f50f00
08e6595
094b3bd
2f50f00
2d60cfa
094b3bd
2f50f00
094b3bd
 
c8d1e1a
094b3bd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2f50f00
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import requests

class TinderWrapper():
  def __init__(self, token):
    self.headers = {
        'Host': 'api.gotinder.com',
        'persistent-device-id': '2A1756C9304C47E39CC4EB52BA002E59',
        'User-Agent': 'Tinder/14.14.0 (iPhone; iOS 16.1; Scale/3.00)',
        'app-session-id': '59B3E862-6B7A-4CFA-8D15-179326473F70',
        'support-short-video': '1',
        'x-hubble-entity-id': 'd213d4fe-239a-4583-87df-8907c6de59ad',
        'app-session-time-elapsed': '2.14300799369812',
        'X-Auth-Token': token,
        'x-supported-image-formats': 'webp, jpeg',
        'platform': 'ios',
        'Connection': 'keep-alive',
        'user-session-time-elapsed': '2.141390085220337',
        'Accept-Language': 'ru',
        'tinder-version': '14.14.0',
        'Accept': 'application/json',
        'app-version': '5363',
        'user-session-id': 'D31F92A9-C94B-478F-A3FB-05531B18758F',
        'os-version': '160000100000',
        'Content-Type': 'application/json'
      }
    self.host = 'https://api.gotinder.com'

  def get_updates(self, last_activity_date):
    try:
        url = f"{self.host}/updates"  # Using f-string for formatting
        payload = {"last_activity_date": last_activity_date}
        response = requests.post(url, headers=self.headers, json=payload)  # Using json parameter instead of manually converting to JSON string
        response.raise_for_status()  # Raises an exception for 4xx or 5xx status codes
        return response.json()
    except requests.exceptions.RequestException as e:
        print(e)

  def get_photos(self, person):
    return [photo['url'] for photo in person['photos']]

  def create_dump(self, update_progress, max_percent=0.5, last_activity_date='1997-03-25T22:49:41.151Z'):
    update_progress(0, 'Выполняю запрос в Tinder...')
    updates = self.get_updates(last_activity_date)['matches']
    update_progress(0, 'Обрабатываю ответ Tinder...')
    
    output = {}
    total_updates = len(updates)

    for i, update in enumerate(updates):
        person = update['person']
        photos = self.get_photos(person)
        person_id = person['_id']
        name = person['name']
        messages = update['messages']
        
        output[person_id] = {
            'name': name,
            'messages': messages,
            'photos': photos
        }
        
        percent = ((i + 1) / total_updates) * max_percent
        update_progress(percent, 'Обрабатываю ответ Tinder...')

    return output