soiz1 commited on
Commit
2324d33
·
verified ·
1 Parent(s): 17dc697

Delete app.py

Browse files
Files changed (1) hide show
  1. app.py +0 -86
app.py DELETED
@@ -1,86 +0,0 @@
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
- import shutil
8
- import stat
9
- import logging
10
-
11
- # ロギング設定
12
- logging.basicConfig(level=logging.INFO, format="%(asctime)s [%(levelname)s] %(message)s")
13
-
14
- # 定数
15
- REPO_URL = "https://github.com/SharkPool-SP/SharkPools-Extensions.git"
16
- REPO_DIR = "SharkPools-Extensions"
17
- TARGET_FILE = os.path.join(REPO_DIR, "pages", "startup.js")
18
-
19
- # Flask アプリケーション設定
20
- app = Flask(__name__, template_folder="templates", static_folder="static")
21
-
22
- @app.route("/")
23
- def index():
24
- return render_template("index.html")
25
-
26
- @app.route('/static/<path:filename>')
27
- def serve_static(filename):
28
- return send_from_directory(app.static_folder, filename)
29
-
30
- # 読み取り専用ファイルを削除できるようにする
31
- def remove_readonly(func, path, excinfo):
32
- os.chmod(path, stat.S_IWRITE)
33
- func(path)
34
-
35
- # リポジトリをクローンまたは更新し、ファイルを修正・コピーする関数
36
- def clone_or_update_repo():
37
- logging.info("リポジトリの更新を開始します。")
38
-
39
- if not os.path.exists(REPO_DIR):
40
- logging.info("リポジトリをクローン中...")
41
- subprocess.run(["git", "clone", REPO_URL])
42
- else:
43
- logging.info("リポジトリをプル中...")
44
- result = subprocess.run(["git", "-C", REPO_DIR, "pull"], capture_output=True, text=True)
45
- logging.info(result.stdout)
46
- if result.stderr:
47
- logging.error(result.stderr)
48
-
49
- if os.path.exists(TARGET_FILE):
50
- logging.info("startup.js を修正中...")
51
- with open(TARGET_FILE, "r", encoding="utf-8") as f:
52
- content = f.read()
53
- new_content = content.replace("https://studio.penguinmod.com", "*")
54
- with open(TARGET_FILE, "w", encoding="utf-8") as f:
55
- f.write(new_content)
56
-
57
- logging.info("テンプレートと静的ファイルをコピー中...")
58
- os.makedirs("templates", exist_ok=True)
59
- shutil.copy(os.path.join(REPO_DIR, "index.html"), "templates/index.html")
60
-
61
- dest_pages = os.path.join("static", "pages")
62
- if os.path.exists(dest_pages):
63
- shutil.rmtree(dest_pages, onerror=remove_readonly)
64
- os.makedirs("static", exist_ok=True)
65
- shutil.copytree(os.path.join(REPO_DIR, "pages"), dest_pages)
66
-
67
- logging.info("リポジトリの更新が完了しました。")
68
-
69
- # スケジューラを実行する関数(1分ごと)
70
- def run_scheduler():
71
- schedule.every(1).minutes.do(clone_or_update_repo)
72
- try:
73
- while True:
74
- schedule.run_pending()
75
- time.sleep(1)
76
- except Exception as e:
77
- logging.error(f"スケジューラでエラーが発生しました: {e}")
78
-
79
- # 初回実行およびスケジューラ起動
80
- clone_or_update_repo()
81
- scheduler_thread = threading.Thread(target=run_scheduler, daemon=True)
82
- scheduler_thread.start()
83
-
84
- # アプリ起動
85
- if __name__ == "__main__":
86
- app.run(debug=True, host="0.0.0.0", port=7860)