def like(self, event): if self.pair_id: try: photos = ','.join([ f'photo{self.pair_id}_{photo}' for photo in Vkfunc.get_photos(self.pair_id) ]) name = " ".join(Vkfunc.get_user_name(self.pair_id)) try: db_func.add_to_whitelist(event.user_id, self.pair_id, photos, name, Vkfunc.get_url(self.pair_id)) except IntegrityError: db_func.add_to_users(Vkfunc.get_user(event.user_id)) db_func.add_to_whitelist(event.user_id, self.pair_id, photos, name, Vkfunc.get_url(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 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 test_get_photos(self): assert Vkfunc.get_photos(1, count=1) == [215187843]