def create_view_content_of_category(category_id): """ view = {"--Заголовки":"Ссылки"} view_string = "" keyword = execute("get_category_name_by_id", category_id=category_id) if keyword == (): return "Нет категории с таким ID" keyword = keyword[0][0] result = execute("get_content_of_category",category_id=category_id) if result == (): return "У этой категории пока нет контента" for content in result: view = dict(view, **unparse.get_links(content[0], keyword)) for key,value in view.items(): view_string += "--{}.\n {}\n".format(key,value) return view_string """ result = execute("get_content_of_category", category_id=category_id) if result == (): return "Нет ресурсов" view = '' for cont in result: view += '{}. {}\n'.format(cont[0], cont[1]) return view
def create_view_subscribe_to_category(category_id, user_id): r = execute("subscribe_to_category", category_id=category_id, user_id=user_id) if r == 1: return "Подписка на категорию прошла успешно" else: return "Ошибка подписки на категорию"
def create_view_add_content(category_id, source, user_id): r = execute("add_content_from_user", category_id=category_id, source=source, user_id=user_id) if (r == 1): return "Добавление содержания прошло успешно" elif (r == 0): return "Ошибка добавления содержания"
def create_view_leave_from_category(user_id, category_id): view = "" result = execute("leave_from_category", category_id=category_id, user_id=user_id) if result == 1: view += "Успешно удалено" else: view += "Вы не подписаны на эту категорию" return view
def search(): cat_list = execute("get_categories") for cat in cat_list: cat_users = execute("get_category_subscribers", category_id=cat[0]) if cat_users == (): continue cont_corts = execute("get_content_of_category", category_id=cat[0]) if cont_corts == (): continue cont_list = [] for cont in cont_corts: cont_list.append(cont[0]) # search_result = requests.post('https://andreytyu.pythonanywhere.com/getLinks', json={"get_links":True, "site":cont_list, "keyword":cat[1]}) search_result = main.create_view_search(cont_list, cat[1]) # view = main.create_view_form_digest(search_result.json()) for user in cat_users: vk_module.send_message(user[0], search_result)
def create_view_delete_source(content_id, user_id, category_id): view = "" result = execute("delete_source", content_id=content_id, user_id=user_id, category_id=category_id) if result == 1: view += "Успешно удалено" else: view += "Ошибка удаления" return view
def create_view_add_user(user_id): r = execute("add_user", user_id=user_id) if (r == 1): return "Добавление пользователя прошло успешно" elif (r == 0): return "Ошибка добавления пользователя"
def create_view_get_categories(): view = "" result = execute("get_categories") for cortege in result: view += "{}. {}\n".format(str(cortege[0]), cortege[1]) return view
def create_view_add_category(category_name): r = execute("add_category", category_name=category_name) if (r == 1): return "Добавление категории прошло успешно" elif (r == 0): return "Ошибка добавления категории"