22 lines
609 B
Python
22 lines
609 B
Python
import requests
|
|
import time
|
|
import re
|
|
|
|
s = requests.Session()
|
|
|
|
def get_cnb_weburl(port):
|
|
s.headers= {"Authorization": "2hk178fffIx8tdXLD9YjYJot0gA"}
|
|
|
|
res = s.get("https://api.cnb.cool/workspace/list?branch=main&status=running").json()
|
|
info = res["list"][0]
|
|
urlinfo = s.get(f"https://api.cnb.cool/{info['slug']}/-/workspace/detail/{info['sn']}").json()
|
|
|
|
#re提取cnb-id
|
|
pattern = r'cnb-[a-z0-9]+-[a-z0-9]+-\d+'
|
|
match = re.search(pattern, urlinfo["webide"])
|
|
if match:
|
|
cnb_id = match.group(0)
|
|
else:
|
|
cnb_id = None
|
|
|
|
return f"https://{cnb_id}-{port}.cnb.run/" |