Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from pywebcopy import save_website
|
3 |
+
import os
|
4 |
+
import shutil
|
5 |
+
import uuid
|
6 |
+
import zipfile
|
7 |
+
|
8 |
+
def download_and_zip_website(url):
|
9 |
+
# 一時フォルダの作成
|
10 |
+
project_id = str(uuid.uuid4())
|
11 |
+
base_path = f"./temp/{project_id}"
|
12 |
+
os.makedirs(base_path, exist_ok=True)
|
13 |
+
|
14 |
+
try:
|
15 |
+
# Webサイトをダウンロード
|
16 |
+
save_website(
|
17 |
+
url=url,
|
18 |
+
project_folder=base_path,
|
19 |
+
project_name="site_copy",
|
20 |
+
bypass_robots=True,
|
21 |
+
debug=True
|
22 |
+
)
|
23 |
+
|
24 |
+
# ZIPファイルを作成
|
25 |
+
zip_path = f"./temp/{project_id}.zip"
|
26 |
+
with zipfile.ZipFile(zip_path, 'w', zipfile.ZIP_DEFLATED) as zipf:
|
27 |
+
for root, dirs, files in os.walk(base_path):
|
28 |
+
for file in files:
|
29 |
+
filepath = os.path.join(root, file)
|
30 |
+
arcname = os.path.relpath(filepath, base_path)
|
31 |
+
zipf.write(filepath, arcname=arcname)
|
32 |
+
|
33 |
+
return zip_path
|
34 |
+
|
35 |
+
except Exception as e:
|
36 |
+
return f"エラー: {e}"
|
37 |
+
|
38 |
+
with gr.Blocks() as demo:
|
39 |
+
gr.Markdown("# 🌐 Webサイトミラー(ZIPダウンロード付き)")
|
40 |
+
with gr.Row():
|
41 |
+
url_input = gr.Textbox(label="URLを入力してください", placeholder="https://example.com")
|
42 |
+
download_button = gr.Button("サイトをダウンロード")
|
43 |
+
result = gr.File(label="ダウンロードリンク(ZIP)")
|
44 |
+
|
45 |
+
download_button.click(
|
46 |
+
fn=download_and_zip_website,
|
47 |
+
inputs=url_input,
|
48 |
+
outputs=result
|
49 |
+
)
|
50 |
+
|
51 |
+
demo.launch()
|