acecalisto3 commited on
Commit
70be69d
·
verified ·
1 Parent(s): 77e1548

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -21
app.py CHANGED
@@ -12,6 +12,7 @@ import os
12
  import datetime
13
  from urllib.parse import urlparse
14
  from bs4 import BeautifulSoup
 
15
 
16
  # Configure logging
17
  logging.basicConfig(level=logging.INFO,
@@ -212,26 +213,26 @@ def process_urls(url_input, bulk_toggle, action_radio, max_urls, crawl_depth, pr
212
  # Update progress
213
  progress((idx + 1) / total_urls)
214
 
215
- # Create ZIP file in memory
216
- memory_file = io.BytesIO()
217
- with zipfile.ZipFile(memory_file, 'w', zipfile.ZIP_DEFLATED) as zipf:
218
- # Add screenshots to ZIP
219
- for screenshot_url, screenshot_data in screenshots:
220
- sanitized_screenshot_url = sanitize_filename(screenshot_url)
221
- filename = f"{sanitized_screenshot_url}.png"
222
- zipf.writestr(filename, screenshot_data)
 
 
 
 
 
 
 
 
 
223
 
224
- # Add scraped data and changes log to ZIP
225
- if scraped_data:
226
- data_to_save = {
227
- 'scraped_data': scraped_data,
228
- 'changes_log': changes_log,
229
- 'timestamp': datetime.datetime.now().isoformat()
230
- }
231
- zipf.writestr('data.json', json.dumps(data_to_save, indent=2))
232
-
233
- # Prepare return values
234
- memory_file.seek(0)
235
 
236
  # Prepare display data
237
  display_data = {
@@ -240,8 +241,8 @@ def process_urls(url_input, bulk_toggle, action_radio, max_urls, crawl_depth, pr
240
  'changes_detected': changes_log
241
  }
242
 
243
- # Return ZIP bytes and display data
244
- return memory_file, json.dumps(display_data, indent=2)
245
 
246
  def create_interface():
247
  """Create the Gradio interface."""
 
12
  import datetime
13
  from urllib.parse import urlparse
14
  from bs4 import BeautifulSoup
15
+ import tempfile
16
 
17
  # Configure logging
18
  logging.basicConfig(level=logging.INFO,
 
213
  # Update progress
214
  progress((idx + 1) / total_urls)
215
 
216
+ # Create a temporary file to store the ZIP
217
+ with tempfile.NamedTemporaryFile(delete=False, suffix=".zip") as tmp_file:
218
+ with zipfile.ZipFile(tmp_file, 'w', zipfile.ZIP_DEFLATED) as zipf:
219
+ # Add screenshots to ZIP
220
+ for screenshot_url, screenshot_data in screenshots:
221
+ sanitized_screenshot_url = sanitize_filename(screenshot_url)
222
+ filename = f"{sanitized_screenshot_url}.png"
223
+ zipf.writestr(filename, screenshot_data)
224
+
225
+ # Add scraped data and changes log to ZIP
226
+ if scraped_data:
227
+ data_to_save = {
228
+ 'scraped_data': scraped_data,
229
+ 'changes_log': changes_log,
230
+ 'timestamp': datetime.datetime.now().isoformat()
231
+ }
232
+ zipf.writestr('data.json', json.dumps(data_to_save, indent=2))
233
 
234
+ # Get the path to the temporary file
235
+ zip_file_path = tmp_file.name
 
 
 
 
 
 
 
 
 
236
 
237
  # Prepare display data
238
  display_data = {
 
241
  'changes_detected': changes_log
242
  }
243
 
244
+ # Return the path to the temporary ZIP file and display data
245
+ return zip_file_path, json.dumps(display_data, indent=2)
246
 
247
  def create_interface():
248
  """Create the Gradio interface."""