Spaces:
Runtime error
Runtime error
Bug fix
Browse files- common/tinderwrapper.py +10 -4
common/tinderwrapper.py
CHANGED
@@ -1,4 +1,5 @@
|
|
1 |
import requests
|
|
|
2 |
|
3 |
class TinderWrapper():
|
4 |
def __init__(self, token):
|
@@ -31,22 +32,27 @@ class TinderWrapper():
|
|
31 |
payload = {"last_activity_date": last_activity_date}
|
32 |
response = requests.post(url, headers=self.headers, json=payload) # Using json parameter instead of manually converting to JSON string
|
33 |
response.raise_for_status() # Raises an exception for 4xx or 5xx status codes
|
34 |
-
return response.json()
|
35 |
except requests.exceptions.RequestException as e:
|
36 |
print(e)
|
|
|
37 |
|
38 |
def get_photos(self, person):
|
39 |
return [photo['url'] for photo in person['photos']]
|
40 |
|
41 |
def create_dump(self, update_progress, max_percent=0.5, last_activity_date='1997-03-25T22:49:41.151Z'):
|
42 |
update_progress(0, 'Выполняю запрос в Tinder...')
|
43 |
-
updates = self.get_updates(last_activity_date)
|
|
|
|
|
|
|
|
|
44 |
update_progress(0, 'Обрабатываю ответ Tinder...')
|
45 |
|
46 |
output = {}
|
47 |
-
total_updates = len(updates)
|
48 |
|
49 |
-
for i, update in enumerate(updates):
|
50 |
person = update['person']
|
51 |
photos = self.get_photos(person)
|
52 |
person_id = person['_id']
|
|
|
1 |
import requests
|
2 |
+
import streamlit as st
|
3 |
|
4 |
class TinderWrapper():
|
5 |
def __init__(self, token):
|
|
|
32 |
payload = {"last_activity_date": last_activity_date}
|
33 |
response = requests.post(url, headers=self.headers, json=payload) # Using json parameter instead of manually converting to JSON string
|
34 |
response.raise_for_status() # Raises an exception for 4xx or 5xx status codes
|
35 |
+
return response.status_code, response.json()
|
36 |
except requests.exceptions.RequestException as e:
|
37 |
print(e)
|
38 |
+
return response.status_code, None
|
39 |
|
40 |
def get_photos(self, person):
|
41 |
return [photo['url'] for photo in person['photos']]
|
42 |
|
43 |
def create_dump(self, update_progress, max_percent=0.5, last_activity_date='1997-03-25T22:49:41.151Z'):
|
44 |
update_progress(0, 'Выполняю запрос в Tinder...')
|
45 |
+
code, updates = self.get_updates(last_activity_date)
|
46 |
+
|
47 |
+
if not code == 200:
|
48 |
+
st.error('Неверный токен доступа')
|
49 |
+
|
50 |
update_progress(0, 'Обрабатываю ответ Tinder...')
|
51 |
|
52 |
output = {}
|
53 |
+
total_updates = len(updates['matches'])
|
54 |
|
55 |
+
for i, update in enumerate(updates['matches']):
|
56 |
person = update['person']
|
57 |
photos = self.get_photos(person)
|
58 |
person_id = person['_id']
|