|
|
from datetime import datetime |
|
|
import pytz |
|
|
import time |
|
|
|
|
|
while True: |
|
|
|
|
|
|
|
|
china_tz = pytz.timezone('Asia/Shanghai') |
|
|
now = datetime.now(china_tz) |
|
|
if now.hour == 6 and now.minute < 2: |
|
|
print(f"当前时间: {now.strftime('%Y-%m-%d %H:%M:%S')}, 到达早上6点,退出循环") |
|
|
break |
|
|
else: |
|
|
print(f"当前时间: {now.strftime('%Y-%m-%d %H:%M:%S')}, 未到达早上6点") |
|
|
time.sleep(5) |
|
|
import requests |
|
|
|
|
|
def _reconstruct_token(partial_token): |
|
|
""" |
|
|
重构完整的 token |
|
|
|
|
|
:param partial_token: 部分 token |
|
|
:return: 完整的 token |
|
|
""" |
|
|
return partial_token.replace(" ", "") |
|
|
|
|
|
def restart_huggingface_space(space_name, space_id, partial_token): |
|
|
""" |
|
|
重启 Hugging Face Space |
|
|
|
|
|
:param space_name: Space 的命名空间 |
|
|
:param space_id: Space 的 ID |
|
|
:param partial_token: Hugging Face 部分访问令牌 |
|
|
:return: 响应结果字典 |
|
|
""" |
|
|
|
|
|
token = _reconstruct_token(partial_token) |
|
|
|
|
|
url = f"https://huggingface.co/api/spaces/{space_name}/{space_id}/restart?factory=true" |
|
|
headers = { |
|
|
"Content-Type": "application/json", |
|
|
"Authorization": f"Bearer {token}", |
|
|
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/137.0.0.0 Safari/537.36" |
|
|
} |
|
|
|
|
|
try: |
|
|
response = requests.post(url, headers=headers, json={}) |
|
|
return { |
|
|
"status_code": response.status_code, |
|
|
"success": response.status_code == 200, |
|
|
"message": response.text |
|
|
} |
|
|
except requests.RequestException as e: |
|
|
return { |
|
|
"status_code": None, |
|
|
"success": False, |
|
|
"message": str(e) |
|
|
} |
|
|
|
|
|
|
|
|
result = restart_huggingface_space("Qi28s", "zz", "hf_bHdgZHDe QHDHtoMjyIgpKvICbNbWJcTDTG") |
|
|
print(result) |