Spaces:
Runtime error
Runtime error
import requests | |
import streamlit as st | |
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.status_code, response.json() | |
except requests.exceptions.RequestException as e: | |
print(e) | |
return response.status_code, None | |
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...') | |
code, updates = self.get_updates(last_activity_date) | |
if not code == 200: | |
raise Exception('Неверный токен доступа!') | |
update_progress(0, 'Обрабатываю ответ Tinder...') | |
output = {} | |
total_updates = len(updates['matches']) | |
for i, update in enumerate(updates['matches']): | |
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 |