Exemplo n.º 1
0
 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)
Exemplo n.º 2
0
 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())
Exemplo n.º 3
0
 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)
Exemplo n.º 4
0
 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())
Exemplo n.º 5
0
 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)
Exemplo n.º 6
0
 def test_get_user(self):
     assert Vkfunc.get_user(1) == data.pavel_durov_user_data
Exemplo n.º 7
0
 def test_get_user_name(self):
     assert Vkfunc.get_user_name(1) == ['Павел', 'Дуров']
Exemplo n.º 8
0
 def test_get_url(self):
     assert Vkfunc.get_url(1) == 'https://vk.com/durov'
Exemplo n.º 9
0
 def test_search_users(self):
     assert Vkfunc.search_users(
         {}, count=1, q='Павел Дуров') == [[1, 'https://vk.com/durov']]
Exemplo n.º 10
0
 def what_sex(self, event):
     return Vkfunc.write_msg(event.user_id, f'Выберите пол',
                             kb.sex_keyboard())
Exemplo n.º 11
0
 def what_age(self, event):
     return Vkfunc.write_msg(event.user_id,
                             f'Введите возраст в формате "от _ до _"')
Exemplo n.º 12
0
 def incorrect_input(self, event):
     return Vkfunc.write_msg(event.user_id,
                             f'Не поняла вашего ответа... 🤔',
                             kb.start_keyboard(self.search_params))
Exemplo n.º 13
0
 def test_get_city_name(self):
     assert Vkfunc.get_city_name(141) == 'Тверь'
Exemplo n.º 14
0
 def what_city(self, event):
     return Vkfunc.write_msg(event.user_id, f'Введите название города')
Exemplo n.º 15
0
 def stop(self, event, cls):
     cls.search_params.clear()
     return Vkfunc.write_msg(event.user_id, 'Пока((')
Exemplo n.º 16
0
 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)
Exemplo n.º 17
0
 def test_get_photos(self):
     assert Vkfunc.get_photos(1, count=1) == [215187843]
Exemplo n.º 18
0
 def what_status(self, event):
     return Vkfunc.write_msg(event.user_id, f'Выберите статус',
                             kb.status_keyboard())
Exemplo n.º 19
0
 def test_get_city(self):
     assert Vkfunc.get_city('Тверь') == 141
Exemplo n.º 20
0
 def city(self, event, request):
     self.search_params['city'] = Vkfunc.get_city(request)
     return self.clarify_message(event)
Exemplo n.º 21
0
 def test_write_msg(self):
     assert Vkfunc.write_msg(data.user['vk_id'], 'test') is True
Exemplo n.º 22
0
 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))