def start(self, event): try: return Vkfunc.write_msg( event.user_id, f'Хай, {db_func.user_info(event.user_id)["first_name"]}!', kb.start_keyboard(dict())) except NoResultFound: db_func.add_to_users(Vkfunc.get_user(event.user_id)) return self.start(event)
def show(self, event): try: self.whitelist = iter(db_func.show_whitelist(event.user_id)) self.pair_id, name, photos, url = next(self.whitelist) return Vkfunc.write_msg(event.user_id, f'{name}, {url}', attachment=photos, keyboard=kb.whitelist_keyboard(url)) except StopIteration: return Vkfunc.write_msg(event.user_id, f'Список понравившихся пуст 😔', kb.back_button())
def next(self, event): try: self.pair_id, name, photos, url = next(self.whitelist) return Vkfunc.write_msg(event.user_id, f'{name}, {url}', attachment=photos, keyboard=kb.whitelist_keyboard(url)) except StopIteration: return self.show(event)
def search(self, event, offset=None): self.search_list = iter( Vkfunc.search_users(self.search_params, offset=offset)) self.marked_list = db_func.marked_ids(event.user_id) try: self.pair_id, url = next(self.search_list) while self.pair_id in self.marked_list: self.pair_id, url = next(self.search_list) photos = ','.join([ f'photo{self.pair_id}_{photo}' for photo in Vkfunc.get_photos(self.pair_id) ]) return self.search_message(event, url, photos) except StopIteration: return Vkfunc.write_msg( event.user_id, f'По такому запросу никого не найдено 😔', kb.back_button())
def not_like(self, event): if self.pair_id: try: try: db_func.add_to_blacklist(event.user_id, self.pair_id) except IntegrityError: db_func.add_to_users(Vkfunc.get_user(event.user_id)) db_func.add_to_blacklist(event.user_id, self.pair_id) self.pair_id, url = next(self.search_list) while self.pair_id in self.marked_list: self.pair_id, url = next(self.search_list) photos = ','.join([ f'photo{self.pair_id}_{photo}' for photo in Vkfunc.get_photos(self.pair_id) ]) return self.search_message(event, url, photos) except StopIteration: self.search(event, offset=len(list(self.search_list))) else: return self.clarify_message(event)
def test_get_user(self): assert Vkfunc.get_user(1) == data.pavel_durov_user_data
def test_get_user_name(self): assert Vkfunc.get_user_name(1) == ['Павел', 'Дуров']
def test_get_url(self): assert Vkfunc.get_url(1) == 'https://vk.com/durov'
def test_search_users(self): assert Vkfunc.search_users( {}, count=1, q='Павел Дуров') == [[1, 'https://vk.com/durov']]
def what_sex(self, event): return Vkfunc.write_msg(event.user_id, f'Выберите пол', kb.sex_keyboard())
def what_age(self, event): return Vkfunc.write_msg(event.user_id, f'Введите возраст в формате "от _ до _"')
def incorrect_input(self, event): return Vkfunc.write_msg(event.user_id, f'Не поняла вашего ответа... 🤔', kb.start_keyboard(self.search_params))
def test_get_city_name(self): assert Vkfunc.get_city_name(141) == 'Тверь'
def what_city(self, event): return Vkfunc.write_msg(event.user_id, f'Введите название города')
def stop(self, event, cls): cls.search_params.clear() return Vkfunc.write_msg(event.user_id, 'Пока((')
def search_message(self, event, url, photos): return Vkfunc.write_msg( event.user_id, f'{" ".join(Vkfunc.get_user_name(self.pair_id))}\n{url}', kb.main_keyboard(), attachment=photos)
def test_get_photos(self): assert Vkfunc.get_photos(1, count=1) == [215187843]
def what_status(self, event): return Vkfunc.write_msg(event.user_id, f'Выберите статус', kb.status_keyboard())
def test_get_city(self): assert Vkfunc.get_city('Тверь') == 141
def city(self, event, request): self.search_params['city'] = Vkfunc.get_city(request) return self.clarify_message(event)
def test_write_msg(self): assert Vkfunc.write_msg(data.user['vk_id'], 'test') is True
def clarify_message(self, event): return Vkfunc.write_msg( event.user_id, f'Уточните параметры поиска или нажмите начать поиск:\n{message_text(self.search_params)}', kb.start_keyboard(self.search_params))