def import_pipelines(site,pipelines):
    headers = build_headers(login(site))
    for pipeline in pipelines:
        response = requests.post(site["host"] + "import/admin/pipeline", data=json.dumps(pipeline),
                                 headers=headers)
        if response.status_code == 200:
            print("import successfully")
def import_topics(site,topics):
    headers = build_headers(login(site))
    for topic in topics:
        # print(topic["name"])
        response = requests.post(site["host"] + "import/admin/topic", data=json.dumps(topic),
                                 headers=headers)
        if response.status_code==200:
            print("import successfully")
def import_users(site,user):
    headers = {"Content-Type": "application/json"}
    user_site = site.copy()
    user_site["username"]="******"
    user_site["password"]= "******"
    headers = build_headers(login(user_site))
    # for user in users:
    response = requests.post(site["host"] + "user", data=json.dumps(user),
                                 headers=headers)

    if response.status_code == 200:
        print("import successfully")
def import_instances(instances, site=None):
    headers = build_headers(login(site))
    results = []
    for instance in instances:
        response = requests.post(site["host"] + "topic/data",
                                 data=json.dumps(instance),
                                 headers=headers)
        if response.status_code == 200:
            results.append(response.json())
        else:
            print(response.text)
    return results
def get_topic_definition_list(site):
    headers = build_headers(login(site))
    response = requests.get(site["host"] + "topic/all"
                            , headers=headers)
    return  response.json()
def load_topic_data_all(topic_name, site):
    headers = build_headers(login(site))
    response = requests.get(site["host"] + "topic/data/all?topic_name=" +
                            topic_name,
                            headers=headers)
    return response.json()
def get_value_from_subject(query, site):
    headers = build_headers(login(site))
    response = requests.post(site["host"] + "subject/query",
                             data=json.dumps(query),
                             headers=headers)
    return response.json()
def remove_topic_collection(collections, site):
    headers = build_headers(login(site))
    response = requests.post(site["host"] + "topic/data/remove",
                             data=json.dumps(collections),
                             headers=headers)