Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -0,0 +1,55 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from flask import Flask, render_template, send_from_directory
|
| 2 |
+
import schedule
|
| 3 |
+
import threading
|
| 4 |
+
import time
|
| 5 |
+
import subprocess
|
| 6 |
+
import os
|
| 7 |
+
|
| 8 |
+
REPO_URL = "https://github.com/SharkPool-SP/SharkPools-Extensions.git"
|
| 9 |
+
REPO_DIR = "SharkPools-Extensions"
|
| 10 |
+
TARGET_FILE = os.path.join(REPO_DIR, "pages", "startup.js")
|
| 11 |
+
|
| 12 |
+
app = Flask(__name__, template_folder="templates", static_folder="static")
|
| 13 |
+
|
| 14 |
+
# === ページ表示 ===
|
| 15 |
+
@app.route("/")
|
| 16 |
+
def index():
|
| 17 |
+
return render_template("index.html")
|
| 18 |
+
|
| 19 |
+
@app.route('/static/<path:filename>')
|
| 20 |
+
def serve_static(filename):
|
| 21 |
+
return send_from_directory(app.static_folder, filename)
|
| 22 |
+
|
| 23 |
+
# === リポジトリ更新と加工処理 ===
|
| 24 |
+
def clone_or_update_repo():
|
| 25 |
+
if not os.path.exists(REPO_DIR):
|
| 26 |
+
subprocess.run(["git", "clone", REPO_URL])
|
| 27 |
+
else:
|
| 28 |
+
subprocess.run(["git", "-C", REPO_DIR, "pull"])
|
| 29 |
+
|
| 30 |
+
# JSのURLを置換
|
| 31 |
+
if os.path.exists(TARGET_FILE):
|
| 32 |
+
with open(TARGET_FILE, "r", encoding="utf-8") as f:
|
| 33 |
+
content = f.read()
|
| 34 |
+
new_content = content.replace("https://studio.penguinmod.com", "*")
|
| 35 |
+
with open(TARGET_FILE, "w", encoding="utf-8") as f:
|
| 36 |
+
f.write(new_content)
|
| 37 |
+
|
| 38 |
+
# 必要なファイルをtemplatesとstaticにコピー
|
| 39 |
+
subprocess.run(["cp", os.path.join(REPO_DIR, "index.html"), "templates/index.html"])
|
| 40 |
+
subprocess.run(["cp", "-r", os.path.join(REPO_DIR, "pages"), "static/pages"], check=True)
|
| 41 |
+
|
| 42 |
+
# === スケジューラー ===
|
| 43 |
+
def run_scheduler():
|
| 44 |
+
schedule.every().day.at("00:00").do(clone_or_update_repo)
|
| 45 |
+
while True:
|
| 46 |
+
schedule.run_pending()
|
| 47 |
+
time.sleep(1)
|
| 48 |
+
|
| 49 |
+
# 初期クローンとスケジューラー開始
|
| 50 |
+
clone_or_update_repo()
|
| 51 |
+
scheduler_thread = threading.Thread(target=run_scheduler, daemon=True)
|
| 52 |
+
scheduler_thread.start()
|
| 53 |
+
|
| 54 |
+
if __name__ == "__main__":
|
| 55 |
+
app.run(debug=True, host="0.0.0.0", port=7860)
|