Spaces:
Configuration error
Configuration error
Create utils/zip_generator.py
Browse files- utils/zip_generator.py +20 -0
utils/zip_generator.py
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import zipfile
|
| 3 |
+
from datetime import datetime
|
| 4 |
+
|
| 5 |
+
def create_zip(code_content):
|
| 6 |
+
# Create a temporary directory if it doesn't exist
|
| 7 |
+
os.makedirs("temp", exist_ok=True)
|
| 8 |
+
|
| 9 |
+
# Save the HTML file
|
| 10 |
+
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
|
| 11 |
+
html_path = f"temp/website_{timestamp}.html"
|
| 12 |
+
with open(html_path, "w") as f:
|
| 13 |
+
f.write(code_content)
|
| 14 |
+
|
| 15 |
+
# Create a ZIP file
|
| 16 |
+
zip_path = f"temp/website_{timestamp}.zip"
|
| 17 |
+
with zipfile.ZipFile(zip_path, 'w') as zipf:
|
| 18 |
+
zipf.write(html_path, arcname="index.html")
|
| 19 |
+
|
| 20 |
+
return zip_path
|