Bharathchilaka commited on
Commit
f70e377
·
verified ·
1 Parent(s): dd9afc3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -2
app.py CHANGED
@@ -14,14 +14,30 @@ import zipfile
14
  # -----------------------------------------------------------------------------
15
 
16
  def extract_zip(zip_path, extract_to):
17
- if not os.path.exists(extract_to):
18
  print(f"Extracting {zip_path}...")
19
  with zipfile.ZipFile(zip_path, 'r') as zip_ref:
20
- zip_ref.extractall(extract_to)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
21
  print(f"Extracted {zip_path} to {extract_to}")
22
  else:
23
  print(f"{extract_to} already exists. Skipping extraction.")
24
 
 
25
  extract_zip("templates_clean.zip", "templates")
26
  extract_zip("static.zip", "static")
27
 
 
14
  # -----------------------------------------------------------------------------
15
 
16
  def extract_zip(zip_path, extract_to):
17
+ if not os.path.exists(extract_to) or not os.listdir(extract_to):
18
  print(f"Extracting {zip_path}...")
19
  with zipfile.ZipFile(zip_path, 'r') as zip_ref:
20
+ # Extract to a temporary location first
21
+ temp_extract_path = extract_to + "_temp"
22
+ zip_ref.extractall(temp_extract_path)
23
+
24
+ # Move files if nested inside 'static/' or 'templates/'
25
+ for root, dirs, files in os.walk(temp_extract_path):
26
+ for name in files:
27
+ src_path = os.path.join(root, name)
28
+ # Find relative path from nested folder (e.g. static/style.css)
29
+ relative_path = os.path.relpath(src_path, temp_extract_path)
30
+ dest_path = os.path.join(extract_to, relative_path)
31
+ os.makedirs(os.path.dirname(dest_path), exist_ok=True)
32
+ os.rename(src_path, dest_path)
33
+ # Clean up
34
+ import shutil
35
+ shutil.rmtree(temp_extract_path)
36
  print(f"Extracted {zip_path} to {extract_to}")
37
  else:
38
  print(f"{extract_to} already exists. Skipping extraction.")
39
 
40
+
41
  extract_zip("templates_clean.zip", "templates")
42
  extract_zip("static.zip", "static")
43