File size: 1,189 Bytes
5312808 be8a5d3 1a28ce3 5312808 be8a5d3 b22d44e be8a5d3 63e1b1c be8a5d3 305b2db be8a5d3 63e1b1c be8a5d3 63e1b1c 5312808 7847b1d 5312808 7847b1d 1a28ce3 7847b1d 5312808 7847b1d |
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 |
import os
import shutil
from flask import Flask, send_from_directory, abort
# リポジトリをクローンするディレクトリ
temp_dir = "/tmp/cookieclicker_repo"
# リポジトリのクローンを行う
def clone_repo():
# 一時ディレクトリが存在する場合は削除
if os.path.exists(temp_dir):
shutil.rmtree(temp_dir)
print("Cloning the repository...")
result = os.system(f"git clone https://github.com/ozh/cookieclicker.git {temp_dir}")
if result != 0:
print("Error: Failed to clone the repository.")
else:
# index.htmlをカレントディレクトリに移動
shutil.move(os.path.join(temp_dir, 'index.html'), '.')
# クローンを実行
clone_repo()
# Flaskアプリケーションの設定
app = Flask(__name__)
# ルートでindex.htmlを表示
@app.route('/')
def index():
# index.htmlが存在しない場合は404エラー
if not os.path.exists("index.html"):
return abort(404, description="index.html not found.")
return send_from_directory('.', 'index.html')
if __name__ == '__main__':
# port 7860でFlaskアプリを起動
app.run(host='0.0.0.0', port=7860)
|