soiz1 commited on
Commit
550cc96
·
verified ·
1 Parent(s): db3d506

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -10
app.py CHANGED
@@ -4,6 +4,7 @@ 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"
@@ -11,23 +12,22 @@ 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('/<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()
@@ -35,21 +35,27 @@ def clone_or_update_repo():
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)
 
4
  import time
5
  import subprocess
6
  import os
7
+ import shutil
8
 
9
  REPO_URL = "https://github.com/SharkPool-SP/SharkPools-Extensions.git"
10
  REPO_DIR = "SharkPools-Extensions"
 
12
 
13
  app = Flask(__name__, template_folder="templates", static_folder="static")
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
  def clone_or_update_repo():
24
  if not os.path.exists(REPO_DIR):
25
  subprocess.run(["git", "clone", REPO_URL])
26
+
27
  else:
28
  subprocess.run(["git", "-C", REPO_DIR, "pull"])
29
 
30
+ # startup.js の文字列置換
31
  if os.path.exists(TARGET_FILE):
32
  with open(TARGET_FILE, "r", encoding="utf-8") as f:
33
  content = f.read()
 
35
  with open(TARGET_FILE, "w", encoding="utf-8") as f:
36
  f.write(new_content)
37
 
38
+ # templates フォルダ作成と index.html コピー
39
+ os.makedirs("templates", exist_ok=True)
40
+ shutil.copy(os.path.join(REPO_DIR, "index.html"), "templates/index.html")
41
+
42
+ # static/pages を作成してコピー
43
+ dest_pages = os.path.join("static", "pages")
44
+ if os.path.exists(dest_pages):
45
+ shutil.rmtree(dest_pages)
46
+ os.makedirs("static", exist_ok=True)
47
+ shutil.copytree(os.path.join(REPO_DIR, "pages"), dest_pages)
48
 
 
49
  def run_scheduler():
50
  schedule.every().day.at("00:00").do(clone_or_update_repo)
51
  while True:
52
  schedule.run_pending()
53
  time.sleep(1)
54
 
55
+ # 初回実行 + スケジューラー起動
56
  clone_or_update_repo()
57
  scheduler_thread = threading.Thread(target=run_scheduler, daemon=True)
58
  scheduler_thread.start()
59
 
60
  if __name__ == "__main__":
61
+ app.run(debug=True)