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 * "*")