Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,5 +1,6 @@
|
|
| 1 |
from fastapi import FastAPI
|
| 2 |
import threading
|
|
|
|
| 3 |
app = FastAPI()
|
| 4 |
def bot_run():
|
| 5 |
import os
|
|
@@ -19,6 +20,21 @@ def bot_run():
|
|
| 19 |
status_file.write("1")
|
| 20 |
os.system("python bot_main.py")
|
| 21 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
@app.get("/")
|
| 23 |
def greet_json():
|
| 24 |
threading.Thread(target=bot_run).start()
|
|
|
|
| 1 |
from fastapi import FastAPI
|
| 2 |
import threading
|
| 3 |
+
import requests
|
| 4 |
app = FastAPI()
|
| 5 |
def bot_run():
|
| 6 |
import os
|
|
|
|
| 20 |
status_file.write("1")
|
| 21 |
os.system("python bot_main.py")
|
| 22 |
|
| 23 |
+
|
| 24 |
+
def keep_alive():
|
| 25 |
+
while True:
|
| 26 |
+
try:
|
| 27 |
+
response = requests.get(SPACE_URL)
|
| 28 |
+
print(f"Ping Status: {response.status_code}") # 確保請求成功
|
| 29 |
+
except Exception as e:
|
| 30 |
+
print(f"Error: {e}")
|
| 31 |
+
time.sleep(1) # 每 5 分鐘執行一次
|
| 32 |
+
|
| 33 |
+
SPACE_URL = "https://mke0108-discordbot.hf.space/"
|
| 34 |
+
threading.Thread(target=keep_alive, daemon=True).start()
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
|
| 38 |
@app.get("/")
|
| 39 |
def greet_json():
|
| 40 |
threading.Thread(target=bot_run).start()
|