clearall_notebook_output

import json

import urllib3

base_url_list = ['http://10.47.118.192:8899', 'http://10.47.118.161:8899']

for base_url in base_url_list:

    http = urllib3.PoolManager(timeout=3.0, retries=False)

    url = '{base_url}/api/notebook/'.format(base_url=base_url)

    try:

        r = http.request('GET', url)

    except urllib3.exceptions.NewConnectionError as e:

        print(e)

        print('Connection failed.')

    # print(r.data.decode())

    notebook_list = json.loads(r.data.decode()).get('body')

    notebook_num = len(notebook_list)

    # 获取notebook数量

    print("总notebook数量", notebook_num)

    # 清除notebook输出的结果

    for i in range(notebook_num):

        try:

            noteid = notebook_list[i].get("id")

            notepath = notebook_list[i].get("path")

            print(noteid, notepath)

        except:

            noteid = ""

        target_url = "{base_url}/api/notebook/{i}/clear".format(base_url=base_url, i=noteid)

        try:

            res_clear = r = http.request('PUT', target_url)

            print(res_clear.data.decode())

        except urllib3.exceptions.NewConnectionError:

            print('Connection failed.')

    print(base_url, "处理完毕")

    print(80 * "*")

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容