Spaces:
Paused
Paused
| from flask import Flask, render_template, send_from_directory | |
| import schedule | |
| import threading | |
| import time | |
| import subprocess | |
| import os | |
| REPO_URL = "https://github.com/SharkPool-SP/SharkPools-Extensions.git" | |
| REPO_DIR = "SharkPools-Extensions" | |
| TARGET_FILE = os.path.join(REPO_DIR, "pages", "startup.js") | |
| app = Flask(__name__, template_folder="templates", static_folder="static") | |
| # === ページ表示 === | |
| def index(): | |
| return render_template("index.html") | |
| def serve_static(filename): | |
| return send_from_directory(app.static_folder, filename) | |
| # === リポジトリ更新と加工処理 === | |
| def clone_or_update_repo(): | |
| if not os.path.exists(REPO_DIR): | |
| subprocess.run(["git", "clone", REPO_URL]) | |
| else: | |
| subprocess.run(["git", "-C", REPO_DIR, "pull"]) | |
| # JSのURLを置換 | |
| if os.path.exists(TARGET_FILE): | |
| with open(TARGET_FILE, "r", encoding="utf-8") as f: | |
| content = f.read() | |
| new_content = content.replace("https://studio.penguinmod.com", "*") | |
| with open(TARGET_FILE, "w", encoding="utf-8") as f: | |
| f.write(new_content) | |
| # 必要なファイルをtemplatesとstaticにコピー | |
| subprocess.run(["cp", os.path.join(REPO_DIR, "index.html"), "templates/index.html"]) | |
| subprocess.run(["cp", "-r", os.path.join(REPO_DIR, "pages"), "static/pages"], check=True) | |
| # === スケジューラー === | |
| def run_scheduler(): | |
| schedule.every().day.at("00:00").do(clone_or_update_repo) | |
| while True: | |
| schedule.run_pending() | |
| time.sleep(1) | |
| # 初期クローンとスケジューラー開始 | |
| clone_or_update_repo() | |
| scheduler_thread = threading.Thread(target=run_scheduler, daemon=True) | |
| scheduler_thread.start() | |
| if __name__ == "__main__": | |
| app.run(debug=True, host="0.0.0.0", port=7860) | |