File size: 1,946 Bytes
d772d81
 
 
 
 
 
550cc96
d772d81
b43f3e0
d772d81
b43f3e0
 
 
d772d81
 
 
 
 
 
 
 
 
 
 
 
 
 
550cc96
 
 
 
 
b43f3e0
550cc96
 
d772d81
b43f3e0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d772d81
 
 
 
 
 
550cc96
d772d81
 
 
 
 
35f72da
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
from flask import Flask, render_template, send_from_directory
import schedule
import threading
import time
import subprocess
import os
import shutil

import stat

def remove_readonly(func, path, excinfo):
    os.chmod(path, stat.S_IWRITE)
    func(path)

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"])

    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)

    os.makedirs("templates", exist_ok=True)
    shutil.copy(os.path.join(REPO_DIR, "index.html"), "templates/index.html")

    dest_pages = os.path.join("static", "pages")
    if os.path.exists(dest_pages):
        shutil.rmtree(dest_pages, onerror=remove_readonly)
    os.makedirs("static", exist_ok=True)
    shutil.copytree(os.path.join(REPO_DIR, "pages"), dest_pages)


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")

@app.route("/")
def index():
    return render_template("index.html")

@app.route('/static/<path:filename>')
def serve_static(filename):
    return send_from_directory(app.static_folder, filename)

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)