Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,67 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import shutil
|
3 |
+
import zipfile
|
4 |
+
import requests
|
5 |
+
from flask import Flask, send_file
|
6 |
+
from threading import Thread
|
7 |
+
|
8 |
+
# === 設定 ===
|
9 |
+
repo_owner = "eaglerforge"
|
10 |
+
repo_name = "EaglerForgeInjector"
|
11 |
+
branch = "main"
|
12 |
+
directory = "examplemods"
|
13 |
+
|
14 |
+
api_url = f"https://api.github.com/repos/{repo_owner}/{repo_name}/contents/{directory}?ref={branch}"
|
15 |
+
headers = {"Accept": "application/vnd.github.v3+json"}
|
16 |
+
temp_dir = "temp_examplemods"
|
17 |
+
zip_name = "examplemods.zip"
|
18 |
+
|
19 |
+
app = Flask(__name__)
|
20 |
+
|
21 |
+
def download_directory():
|
22 |
+
os.makedirs(temp_dir, exist_ok=True)
|
23 |
+
response = requests.get(api_url, headers=headers)
|
24 |
+
if response.status_code != 200:
|
25 |
+
raise Exception(f"GitHub API error: {response.status_code} - {response.text}")
|
26 |
+
for file in response.json():
|
27 |
+
if file["type"] == "file":
|
28 |
+
download_url = file["download_url"]
|
29 |
+
local_path = os.path.join(temp_dir, file["name"])
|
30 |
+
print(f"Downloading {file['name']}...")
|
31 |
+
r = requests.get(download_url)
|
32 |
+
with open(local_path, "wb") as f:
|
33 |
+
f.write(r.content)
|
34 |
+
|
35 |
+
def zip_directory():
|
36 |
+
with zipfile.ZipFile(zip_name, "w", zipfile.ZIP_DEFLATED) as zipf:
|
37 |
+
for root, _, files in os.walk(temp_dir):
|
38 |
+
for file in files:
|
39 |
+
file_path = os.path.join(root, file)
|
40 |
+
zipf.write(file_path, os.path.relpath(file_path, temp_dir))
|
41 |
+
print(f"{zip_name} created!")
|
42 |
+
|
43 |
+
@app.route("/")
|
44 |
+
def index():
|
45 |
+
return f'''
|
46 |
+
<h2>ZIPファイルをダウンロード</h2>
|
47 |
+
<a href="/download">examplemods.zip をダウンロード</a>
|
48 |
+
'''
|
49 |
+
|
50 |
+
@app.route("/download")
|
51 |
+
def download_file():
|
52 |
+
return send_file(zip_name, as_attachment=True)
|
53 |
+
|
54 |
+
def start_flask():
|
55 |
+
app.run(host="0.0.0.0", port=7860)
|
56 |
+
|
57 |
+
if __name__ == "__main__":
|
58 |
+
try:
|
59 |
+
download_directory()
|
60 |
+
zip_directory()
|
61 |
+
finally:
|
62 |
+
shutil.rmtree(temp_dir)
|
63 |
+
|
64 |
+
print("ローカルサーバーを起動中... http://localhost:8000/")
|
65 |
+
Thread(target=start_flask).start()
|
66 |
+
|
67 |
+
input("Enterで終了します。")
|