Qilan2 commited on
Commit
4d0a47d
·
verified ·
1 Parent(s): 33d329d

Update ff1.py

Browse files
Files changed (1) hide show
  1. ff1.py +47 -7
ff1.py CHANGED
@@ -208,6 +208,50 @@ def create_space(type,key = "", value = "",name = ""):
208
  # print("推送失败,可能有冲突,尝试拉取并合并...")
209
  # os.system('git pull origin main --rebase')
210
  # os.system('git push origin main')
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
211
  def get_latest_local_package(directory, pattern='*.tar.gz'):
212
  try:
213
  # 构建完整的搜索路径
@@ -596,11 +640,9 @@ def check_system_resources():
596
  create_space(3,"BOT_TOKEN",BOT_TOKEN,tmp_name)
597
  create_space(3,"HF_SPACES_NAME",HF_ID,tmp_name)
598
  time.sleep(2)
599
- create_space(4,"","",tmp_name)
600
- time.sleep(2)
601
  result = restart_huggingface_space(HF_USER2, tmp_name, HF_TOKON2)
602
  print(f"{tmp_name}重启结果:",result)
603
- create_space(4,"","",CHAT_ID)
604
  # result = restart_huggingface_space(HF_USER2, HF_ID, HF_TOKON2)
605
  # print(result)
606
  else:
@@ -624,7 +666,7 @@ if os.path.exists('/data/ff/.mozilla/firefox/profiles.ini') and os.path.isfile('
624
  response = create_space(2)
625
  print(response)
626
  time.sleep(21600)#21600 = 6小时
627
- create_space(4,"","",HF_SPACES_NAME)
628
  response = create_space(1)
629
  url = response["url"]
630
  full_name = response["name"]
@@ -648,12 +690,10 @@ if os.path.exists('/data/ff/.mozilla/firefox/profiles.ini') and os.path.isfile('
648
  create_space(3,"BOT_TOKEN",BOT_TOKEN,tmp_name)
649
  create_space(3,"HF_SPACES_NAME",HF_ID,tmp_name)
650
  time.sleep(2)
651
- create_space(4,"","",tmp_name)
652
- time.sleep(2)
653
  result = restart_huggingface_space(HF_USER2, tmp_name, HF_TOKON2)
654
  print(f"{tmp_name}重启结果:",result)
655
  telegram_message(BOT_TOKEN, CHAT_ID, f"{HF_ID} startup finished")
656
- create_space(4,"","",CHAT_ID)
657
  # result = restart_huggingface_space(HF_USER2, HF_ID, HF_TOKON2)
658
  # print(result)
659
  # break
 
208
  # print("推送失败,可能有冲突,尝试拉取并合并...")
209
  # os.system('git pull origin main --rebase')
210
  # os.system('git push origin main')
211
+ if type == 5:
212
+ # 获取用户的所有空间
213
+ headers = {
214
+ "Authorization": f"Bearer {HF_TOKON2}"
215
+ }
216
+
217
+ # 获取用户的所有空间列表
218
+ response = requests.get(f"https://huggingface.co/api/spaces?author={HF_USER2}", headers=headers)
219
+
220
+ if response.status_code != 200:
221
+ print(f"获取空间列表失败:{response.status_code}")
222
+ return
223
+
224
+ spaces = response.json()
225
+
226
+ # 按创建时间排序
227
+ spaces_sorted = sorted(spaces, key=lambda x: x['createdAt'], reverse=True)
228
+
229
+ # 保留最新的空间
230
+ if len(spaces_sorted) > 1:
231
+ latest_space = spaces_sorted[0]
232
+
233
+ # 遍历并删除其他旧空间
234
+ for space in spaces_sorted[1:]:
235
+ full_name = space['id']
236
+ space_id = full_name.split("/")[-1]
237
+ # 删除spaces
238
+ url = "https://huggingface.co/api/repos/delete"
239
+ headers = {
240
+ "Content-Type": "application/json",
241
+ "Authorization": f"Bearer {HF_TOKON2}"
242
+ }
243
+ payload = {
244
+ "organization": HF_USER2,
245
+ "name": space_id,
246
+ "type": "space"
247
+ }
248
+ delete_response = requests.delete(url, headers=headers, json=payload)
249
+ if delete_response.status_code == 200:
250
+ print(f"成功删除空间:{space_id}")
251
+ telegram_message(BOT_TOKEN, CHAT_ID, f"delete={space_id}=OK")
252
+ else:
253
+ print(f"删除空间 {space_id} 失败:{delete_response.status_code}")
254
+ telegram_message(BOT_TOKEN, CHAT_ID, f"delete={space_id}=ON")
255
  def get_latest_local_package(directory, pattern='*.tar.gz'):
256
  try:
257
  # 构建完整的搜索路径
 
640
  create_space(3,"BOT_TOKEN",BOT_TOKEN,tmp_name)
641
  create_space(3,"HF_SPACES_NAME",HF_ID,tmp_name)
642
  time.sleep(2)
 
 
643
  result = restart_huggingface_space(HF_USER2, tmp_name, HF_TOKON2)
644
  print(f"{tmp_name}重启结果:",result)
645
+ # create_space(4,"","",CHAT_ID)
646
  # result = restart_huggingface_space(HF_USER2, HF_ID, HF_TOKON2)
647
  # print(result)
648
  else:
 
666
  response = create_space(2)
667
  print(response)
668
  time.sleep(21600)#21600 = 6小时
669
+ create_space(5,"","",HF_SPACES_NAME)
670
  response = create_space(1)
671
  url = response["url"]
672
  full_name = response["name"]
 
690
  create_space(3,"BOT_TOKEN",BOT_TOKEN,tmp_name)
691
  create_space(3,"HF_SPACES_NAME",HF_ID,tmp_name)
692
  time.sleep(2)
 
 
693
  result = restart_huggingface_space(HF_USER2, tmp_name, HF_TOKON2)
694
  print(f"{tmp_name}重启结果:",result)
695
  telegram_message(BOT_TOKEN, CHAT_ID, f"{HF_ID} startup finished")
696
+ # create_space(4,"","",CHAT_ID)
697
  # result = restart_huggingface_space(HF_USER2, HF_ID, HF_TOKON2)
698
  # print(result)
699
  # break