Update app.py
Browse files
app.py
CHANGED
|
@@ -1,6 +1,7 @@
|
|
| 1 |
import os
|
| 2 |
import shutil
|
| 3 |
-
from flask import Flask, send_from_directory, abort
|
|
|
|
| 4 |
|
| 5 |
# リポジトリをクローンするディレクトリ
|
| 6 |
temp_dir = "/tmp/cookieclicker_repo"
|
|
@@ -37,7 +38,6 @@ def clone_repo():
|
|
| 37 |
# クローンを実行
|
| 38 |
clone_repo()
|
| 39 |
|
| 40 |
-
|
| 41 |
# Flaskアプリケーションの設定
|
| 42 |
app = Flask(__name__)
|
| 43 |
|
|
@@ -47,7 +47,46 @@ def index():
|
|
| 47 |
# index.htmlが存在しない場合は404エラー
|
| 48 |
if not os.path.exists("index.html"):
|
| 49 |
return abort(404, description="index.html not found.")
|
| 50 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 51 |
|
| 52 |
# 静的ファイルを提供するためのルート
|
| 53 |
@app.route('/<path:filename>')
|
|
|
|
| 1 |
import os
|
| 2 |
import shutil
|
| 3 |
+
from flask import Flask, send_from_directory, abort, render_template_string
|
| 4 |
+
import requests
|
| 5 |
|
| 6 |
# リポジトリをクローンするディレクトリ
|
| 7 |
temp_dir = "/tmp/cookieclicker_repo"
|
|
|
|
| 38 |
# クローンを実行
|
| 39 |
clone_repo()
|
| 40 |
|
|
|
|
| 41 |
# Flaskアプリケーションの設定
|
| 42 |
app = Flask(__name__)
|
| 43 |
|
|
|
|
| 47 |
# index.htmlが存在しない場合は404エラー
|
| 48 |
if not os.path.exists("index.html"):
|
| 49 |
return abort(404, description="index.html not found.")
|
| 50 |
+
|
| 51 |
+
# index.htmlの内容を読み込んで、JavaScriptを動的に追加
|
| 52 |
+
with open("index.html", "r") as file:
|
| 53 |
+
index_html_content = file.read()
|
| 54 |
+
|
| 55 |
+
# JavaScriptコードを追加する部分
|
| 56 |
+
js_code = """
|
| 57 |
+
<script>
|
| 58 |
+
setInterval(() => {
|
| 59 |
+
fetch('https://huggingface.co/spaces/soiz/cookie/raw/main/tof')
|
| 60 |
+
.then(response => response.json())
|
| 61 |
+
.then(data => {
|
| 62 |
+
if (data === 1) {
|
| 63 |
+
const img = document.createElement('img');
|
| 64 |
+
img.src = '/1.png';
|
| 65 |
+
img.style.position = 'fixed';
|
| 66 |
+
img.style.top = '0';
|
| 67 |
+
img.style.left = '0';
|
| 68 |
+
img.style.width = '100vw';
|
| 69 |
+
img.style.height = '100vh';
|
| 70 |
+
img.style.zIndex = '9999';
|
| 71 |
+
document.body.appendChild(img);
|
| 72 |
+
} else if (data === 0) {
|
| 73 |
+
const existingImg = document.querySelector('img');
|
| 74 |
+
if (existingImg) {
|
| 75 |
+
existingImg.remove();
|
| 76 |
+
}
|
| 77 |
+
}
|
| 78 |
+
})
|
| 79 |
+
.catch(error => {
|
| 80 |
+
// エラー時の処理は特にしない
|
| 81 |
+
});
|
| 82 |
+
}, 10000); // 10秒ごとにリクエストを送信
|
| 83 |
+
</script>
|
| 84 |
+
"""
|
| 85 |
+
|
| 86 |
+
# index.htmlのbodyタグの前にJavaScriptを追加
|
| 87 |
+
index_html_content = index_html_content.replace("</body>", js_code + "</body>")
|
| 88 |
+
|
| 89 |
+
return render_template_string(index_html_content)
|
| 90 |
|
| 91 |
# 静的ファイルを提供するためのルート
|
| 92 |
@app.route('/<path:filename>')
|