Update ff1.py
Browse files
ff1.py
CHANGED
|
@@ -13,7 +13,7 @@ import requests
|
|
| 13 |
import json
|
| 14 |
import random
|
| 15 |
import string
|
| 16 |
-
|
| 17 |
|
| 18 |
DATA_JSON = os.environ.get('DATA_JSON', '')
|
| 19 |
HF_SPACES_NAME = os.environ.get('HF_SPACES_NAME', '')# 上个spaces名
|
|
@@ -107,13 +107,14 @@ def telegram_message(bot_token: str, chat_id: str, message: str):
|
|
| 107 |
:param message: 要发送的正文内容
|
| 108 |
:return: Telegram API 返回的结果
|
| 109 |
"""
|
| 110 |
-
url = f"https://
|
| 111 |
params = {
|
| 112 |
"chat_id": chat_id,
|
| 113 |
"text": message,
|
| 114 |
"parse_mode": "MarkdownV2"
|
| 115 |
}
|
| 116 |
-
|
|
|
|
| 117 |
try:
|
| 118 |
return response.json()
|
| 119 |
except Exception:
|
|
@@ -175,7 +176,7 @@ def create_space(type,key = "", value = ""):
|
|
| 175 |
os.system(f'git config --global user.name "{HF_USER2}"')
|
| 176 |
os.chdir(f'/data/{tmp_name}')
|
| 177 |
os.system('rm -rf Dockerfile')
|
| 178 |
-
os.system("wget -O Dockerfile https://huggingface.co/datasets/Qilan2/ff/raw/main/Dockerfile")
|
| 179 |
os.system('git add .')
|
| 180 |
os.system('git commit -m "0"')
|
| 181 |
os.system('git push origin main')
|
|
@@ -502,7 +503,9 @@ def github(type):
|
|
| 502 |
# 轻度清理
|
| 503 |
os.system('git gc --auto')
|
| 504 |
os.system('git lfs prune')
|
|
|
|
| 505 |
else:
|
|
|
|
| 506 |
print("压缩失败,无法提交")
|
| 507 |
|
| 508 |
|
|
@@ -539,13 +542,25 @@ def check_system_resources():
|
|
| 539 |
memory_usage = memory.percent
|
| 540 |
if cpu_usage >= 90 or memory_usage >= 95:
|
| 541 |
print("占用过高")
|
| 542 |
-
create_space(1
|
| 543 |
-
|
| 544 |
-
create_space(3,"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 545 |
create_space(3,"HF_SPACES_NAME",HF_ID)
|
| 546 |
-
create_space(4
|
| 547 |
-
result = restart_huggingface_space(HF_USER2, HF_ID, HF_TOKON2)
|
| 548 |
-
print(result)
|
| 549 |
else:
|
| 550 |
print("系统资源正常")
|
| 551 |
|
|
@@ -561,6 +576,7 @@ github(1)
|
|
| 561 |
|
| 562 |
if os.path.exists('/data/ff/.mozilla/firefox/profiles.ini') and os.path.isfile('/data/ff/.mozilla/firefox/profiles.ini'):
|
| 563 |
threading.Thread(target=repeat_task, daemon=True).start()
|
|
|
|
| 564 |
while True:
|
| 565 |
print("检测到Firefox配置,启动定期重启循环...")
|
| 566 |
response = create_space(2)
|
|
@@ -584,6 +600,7 @@ if os.path.exists('/data/ff/.mozilla/firefox/profiles.ini') and os.path.isfile('
|
|
| 584 |
create_space(3,"BOT_TOKEN",BOT_TOKEN)
|
| 585 |
create_space(3,"HF_SPACES_NAME",HF_ID)
|
| 586 |
create_space(4)
|
|
|
|
| 587 |
# result = restart_huggingface_space(HF_USER2, HF_ID, HF_TOKON2)
|
| 588 |
# print(result)
|
| 589 |
break
|
|
|
|
| 13 |
import json
|
| 14 |
import random
|
| 15 |
import string
|
| 16 |
+
import urllib3
|
| 17 |
|
| 18 |
DATA_JSON = os.environ.get('DATA_JSON', '')
|
| 19 |
HF_SPACES_NAME = os.environ.get('HF_SPACES_NAME', '')# 上个spaces名
|
|
|
|
| 107 |
:param message: 要发送的正文内容
|
| 108 |
:return: Telegram API 返回的结果
|
| 109 |
"""
|
| 110 |
+
url = f"https://tgbotapi.9.c.5.b.0.d.0.0.1.0.a.2.ip6.arpa/bot{bot_token}/sendMessage"
|
| 111 |
params = {
|
| 112 |
"chat_id": chat_id,
|
| 113 |
"text": message,
|
| 114 |
"parse_mode": "MarkdownV2"
|
| 115 |
}
|
| 116 |
+
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
|
| 117 |
+
response = requests.post(url, params=params, verify=False)
|
| 118 |
try:
|
| 119 |
return response.json()
|
| 120 |
except Exception:
|
|
|
|
| 176 |
os.system(f'git config --global user.name "{HF_USER2}"')
|
| 177 |
os.chdir(f'/data/{tmp_name}')
|
| 178 |
os.system('rm -rf Dockerfile')
|
| 179 |
+
os.system(f"wget -O ‘/data/{tmp_name}/Dockerfile’ https://huggingface.co/datasets/Qilan2/ff/raw/main/Dockerfile")
|
| 180 |
os.system('git add .')
|
| 181 |
os.system('git commit -m "0"')
|
| 182 |
os.system('git push origin main')
|
|
|
|
| 503 |
# 轻度清理
|
| 504 |
os.system('git gc --auto')
|
| 505 |
os.system('git lfs prune')
|
| 506 |
+
telegram_message(BOT_TOKEN, CHAT_ID, f"{HF_ID}提交仓库{HF_REPO}结果:{file_size_info}")
|
| 507 |
else:
|
| 508 |
+
telegram_message(BOT_TOKEN, CHAT_ID, f"{HF_ID}提交仓库{HF_REPO}结果:压缩失败,无法提交")
|
| 509 |
print("压缩失败,无法提交")
|
| 510 |
|
| 511 |
|
|
|
|
| 542 |
memory_usage = memory.percent
|
| 543 |
if cpu_usage >= 90 or memory_usage >= 95:
|
| 544 |
print("占用过高")
|
| 545 |
+
response = create_space(1)
|
| 546 |
+
print(response)
|
| 547 |
+
create_space(3,"BACKUP_TIME",BACKUP_TIME)
|
| 548 |
+
create_space(3,"HF_USER1",HF_USER1)
|
| 549 |
+
create_space(3,"HF_REPO",HF_REPO)
|
| 550 |
+
create_space(3,"HF_EMAIL",HF_EMAIL)
|
| 551 |
+
create_space(3,"HF_TOKEN1",HF_TOKEN1)
|
| 552 |
+
create_space(3,"HF_USER2",HF_USER2)
|
| 553 |
+
create_space(3,"HF_EMAIL2",HF_EMAIL2)
|
| 554 |
+
create_space(3,"HF_ID",tmp_name)
|
| 555 |
+
create_space(3,"HF_TOKON2",HF_TOKON2)
|
| 556 |
+
create_space(3,"UUID",UUID)
|
| 557 |
+
create_space(3,"N_SERVER","z.282820.xyz:443")
|
| 558 |
+
create_space(3,"CHAT_ID",CHAT_ID)
|
| 559 |
+
create_space(3,"BOT_TOKEN",BOT_TOKEN)
|
| 560 |
create_space(3,"HF_SPACES_NAME",HF_ID)
|
| 561 |
+
create_space(4)
|
| 562 |
+
# result = restart_huggingface_space(HF_USER2, HF_ID, HF_TOKON2)
|
| 563 |
+
# print(result)
|
| 564 |
else:
|
| 565 |
print("系统资源正常")
|
| 566 |
|
|
|
|
| 576 |
|
| 577 |
if os.path.exists('/data/ff/.mozilla/firefox/profiles.ini') and os.path.isfile('/data/ff/.mozilla/firefox/profiles.ini'):
|
| 578 |
threading.Thread(target=repeat_task, daemon=True).start()
|
| 579 |
+
telegram_message(BOT_TOKEN, CHAT_ID, f"{HF_ID}开始启动")
|
| 580 |
while True:
|
| 581 |
print("检测到Firefox配置,启动定期重启循环...")
|
| 582 |
response = create_space(2)
|
|
|
|
| 600 |
create_space(3,"BOT_TOKEN",BOT_TOKEN)
|
| 601 |
create_space(3,"HF_SPACES_NAME",HF_ID)
|
| 602 |
create_space(4)
|
| 603 |
+
telegram_message(BOT_TOKEN, CHAT_ID, f"{HF_ID}启动结束")
|
| 604 |
# result = restart_huggingface_space(HF_USER2, HF_ID, HF_TOKON2)
|
| 605 |
# print(result)
|
| 606 |
break
|