Spaces:
Running
Running
File size: 3,433 Bytes
216bae4 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
def fetch_all(limit=50):
"""
Vercel API v10/projects๋ฅผ ์ฌ์ฉํ์ฌ ํ๋ก์ ํธ ๋ชฉ๋ก์ ๊ฐ์ ธ์ต๋๋ค.
"""
try:
# API ํ๋ผ๋ฏธํฐ ์ค์
params = {"limit": limit}
if TEAM:
params["teamId"] = TEAM
print(f"Vercel API ํธ์ถ (ํ๋ก์ ํธ): {API}/v10/projects (params={params})")
resp = requests.get(f"{API}/v10/projects",
headers=HEAD, params=params, timeout=30)
print(f"API ์๋ต ์ํ ์ฝ๋: {resp.status_code}")
if resp.status_code != 200:
print(f"API ์๋ต ์ค๋ฅ: {resp.status_code}, {resp.text[:200] if hasattr(resp, 'text') else ''}")
return []
data = resp.json()
if "projects" not in data:
print(f"API ์๋ต์ projects ํ๋๊ฐ ์์ต๋๋ค: {str(data)[:200]}...")
return []
projects = data.get("projects", [])
print(f"{len(projects)}๊ฐ์ ํ๋ก์ ํธ๋ฅผ ์ฐพ์์ต๋๋ค")
# ๊ฐ ํ๋ก์ ํธ์ ์ต์ ๋ฐฐํฌ ์ ๋ณด ๊ฐ์ ธ์ค๊ธฐ
games = []
for project in projects:
project_id = project.get("id")
project_name = project.get("name", "(์ ๋ชฉ ์์)")
# ํ๋ก์ ํธ๋ณ ์ต์ ๋ฐฐํฌ ๊ฐ์ ธ์ค๊ธฐ (projectId ํํฐ ์ถ๊ฐ)
try:
deploy_params = {
"limit": 1,
"projectId": project_id, # ์ค์: ํด๋น ํ๋ก์ ํธ์ ๋ฐฐํฌ๋ง ํํฐ๋ง
"state": "READY"
}
if TEAM:
deploy_params["teamId"] = TEAM
print(f"ํ๋ก์ ํธ {project_id} ({project_name}) ๋ฐฐํฌ ์กฐํ ์ค...")
deploy_resp = requests.get(
f"{API}/v6/deployments",
headers=HEAD,
params=deploy_params,
timeout=30
)
if deploy_resp.status_code == 200:
deploy_data = deploy_resp.json()
deployments = deploy_data.get("deployments", [])
if deployments:
deployment = deployments[0]
url = deployment.get("url", "")
if url:
games.append({
"title": project_name,
"url": f"https://{url}",
"ts": int(deployment.get("created", time.time() * 1000) / 1000),
"projectId": project_id
})
print(f"ํ๋ก์ ํธ {project_name}์ ๋ฐฐํฌ URL: https://{url}")
else:
print(f"ํ๋ก์ ํธ {project_name}์ ๋ฐฐํฌ๋ ๋ฒ์ ์ด ์์ต๋๋ค.")
except Exception as e:
print(f"ํ๋ก์ ํธ {project_id}์ ๋ฐฐํฌ ์ ๋ณด ๊ฐ์ ธ์ค๊ธฐ ์คํจ: {e}")
continue
print(f"์ด {len(games)}๊ฐ์ ์ ํจํ ๋ฐฐํฌ๋ฅผ ์ฐพ์์ต๋๋ค")
return sorted(games, key=lambda x: x["ts"], reverse=True)
except Exception as e:
print(f"Vercel API ์ค๋ฅ: {str(e)}")
import traceback
traceback.print_exc()
return []
|