Update app.py
Browse files
app.py
CHANGED
@@ -1,44 +1,47 @@
|
|
1 |
-
import
|
2 |
-
from tkinter import filedialog, messagebox, ttk
|
3 |
import zipfile
|
4 |
import os
|
5 |
-
import
|
6 |
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
|
|
11 |
|
12 |
-
|
13 |
-
if not extract_to:
|
14 |
-
return
|
15 |
|
16 |
-
|
17 |
-
|
|
|
18 |
|
19 |
-
|
20 |
-
|
21 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
22 |
files = zip_ref.namelist()
|
23 |
total_files = len(files)
|
24 |
|
25 |
for i, file in enumerate(files):
|
26 |
zip_ref.extract(file, extract_to)
|
27 |
-
progress
|
28 |
-
|
29 |
-
|
30 |
-
messagebox.showinfo("Success", f"✅ Extracted to: {extract_to}")
|
31 |
-
except Exception as e:
|
32 |
-
messagebox.showerror("Error", f"❌ Error: {e}")
|
33 |
|
34 |
-
|
35 |
-
root = tk.Tk()
|
36 |
-
root.title("ZIP Extractor")
|
37 |
|
38 |
-
|
39 |
-
button.pack(pady=10)
|
40 |
|
41 |
-
|
42 |
-
|
|
|
43 |
|
44 |
-
|
|
|
|
1 |
+
from flask import Flask, render_template, request, jsonify
|
|
|
2 |
import zipfile
|
3 |
import os
|
4 |
+
import time
|
5 |
|
6 |
+
app = Flask(__name__)
|
7 |
+
UPLOAD_FOLDER = "ipv4"
|
8 |
+
EXTRACT_FOLDER = "ipv4"
|
9 |
+
os.makedirs(UPLOAD_FOLDER, exist_ok=True)
|
10 |
+
os.makedirs(EXTRACT_FOLDER, exist_ok=True)
|
11 |
|
12 |
+
progress = 0 # Global progress variable
|
|
|
|
|
13 |
|
14 |
+
@app.route("/", methods=["GET", "POST"])
|
15 |
+
def index():
|
16 |
+
return render_template("index.html")
|
17 |
|
18 |
+
@app.route("/upload", methods=["POST"])
|
19 |
+
def upload():
|
20 |
+
global progress
|
21 |
+
zip_file = request.files["zip_file"]
|
22 |
+
extract_to = request.form.get("extract_path")
|
23 |
+
|
24 |
+
if zip_file and extract_to:
|
25 |
+
os.makedirs(extract_to, exist_ok=True)
|
26 |
+
zip_path = os.path.join(UPLOAD_FOLDER, zip_file.filename)
|
27 |
+
zip_file.save(zip_path)
|
28 |
+
|
29 |
+
with zipfile.ZipFile(zip_path, 'r') as zip_ref:
|
30 |
files = zip_ref.namelist()
|
31 |
total_files = len(files)
|
32 |
|
33 |
for i, file in enumerate(files):
|
34 |
zip_ref.extract(file, extract_to)
|
35 |
+
progress = ((i + 1) / total_files) * 100
|
36 |
+
time.sleep(0.1) # Simulate progress update
|
|
|
|
|
|
|
|
|
37 |
|
38 |
+
return jsonify({"message": "✅ Extracted Successfully!", "progress": 100})
|
|
|
|
|
39 |
|
40 |
+
return jsonify({"message": "❌ Error Extracting!"}), 400
|
|
|
41 |
|
42 |
+
@app.route("/progress", methods=["GET"])
|
43 |
+
def get_progress():
|
44 |
+
return jsonify({"progress": progress})
|
45 |
|
46 |
+
if __name__ == "__main__":
|
47 |
+
app.run(debug=True)
|