Spaces:
Runtime error
Runtime error
Refactoring + bug fix
Browse files- common/helpers.py +21 -18
- common/tinderwrapper.py +1 -1
common/helpers.py
CHANGED
|
@@ -7,25 +7,28 @@ def download_photo(url, save_path):
|
|
| 7 |
with open(save_path, 'wb') as file:
|
| 8 |
file.write(response.content)
|
| 9 |
|
| 10 |
-
def save_data(dump, dump_folder, update_progress, min_percent=
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
for photo_url in value['photos']:
|
| 17 |
-
file_name = photo_url.split("/")[-1]
|
| 18 |
-
save_path = os.path.join(folder_path, file_name)
|
| 19 |
-
download_photo(photo_url, save_path)
|
| 20 |
-
|
| 21 |
-
with open(os.path.join(folder_path, 'chat.txt'), 'w') as file:
|
| 22 |
-
for message in value['messages']:
|
| 23 |
-
name = f'[{value["name"] if message["from"] == id else "Me"}]'
|
| 24 |
-
file.write(f'{name}: {message["message"]}' + '\n')
|
| 25 |
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
|
| 30 |
def create_folder(folder_name):
|
| 31 |
if os.path.exists(folder_name):
|
|
|
|
| 7 |
with open(save_path, 'wb') as file:
|
| 8 |
file.write(response.content)
|
| 9 |
|
| 10 |
+
def save_data(dump, dump_folder, update_progress, min_percent=0.5):
|
| 11 |
+
total_items = len(dump)
|
| 12 |
+
percent_range = 1 - min_percent
|
| 13 |
+
|
| 14 |
+
update_progress(min_percent, 'Скачиваю изображения и формирую дамп...')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
|
| 16 |
+
for i, (id, value) in enumerate(dump.items(), start=1):
|
| 17 |
+
folder_path = os.path.join(dump_folder, f'{value["name"]}_{id}')
|
| 18 |
+
os.makedirs(folder_path, exist_ok=True)
|
| 19 |
+
|
| 20 |
+
for photo_url in value['photos']:
|
| 21 |
+
file_name = photo_url.split("/")[-1]
|
| 22 |
+
save_path = os.path.join(folder_path, file_name)
|
| 23 |
+
download_photo(photo_url, save_path)
|
| 24 |
+
|
| 25 |
+
with open(os.path.join(folder_path, 'chat.txt'), 'w') as file:
|
| 26 |
+
for message in value['messages']:
|
| 27 |
+
name = f'[{value["name"] if message["from"] == id else "Me"}]'
|
| 28 |
+
file.write(f'{name}: {message["message"]}\n')
|
| 29 |
+
|
| 30 |
+
percent = ((i / total_items) * percent_range + min_percent)
|
| 31 |
+
update_progress(percent, 'Скачиваю изображения и формирую дамп...')
|
| 32 |
|
| 33 |
def create_folder(folder_name):
|
| 34 |
if os.path.exists(folder_name):
|
common/tinderwrapper.py
CHANGED
|
@@ -38,7 +38,7 @@ class TinderWrapper():
|
|
| 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=
|
| 42 |
update_progress(0, 'Выполняю запрос в Tinder...')
|
| 43 |
updates = self.get_updates(last_activity_date)['matches']
|
| 44 |
update_progress(0, 'Обрабатываю ответ Tinder...')
|
|
|
|
| 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)['matches']
|
| 44 |
update_progress(0, 'Обрабатываю ответ Tinder...')
|