Freak-ppa commited on
Commit
0836393
·
verified ·
1 Parent(s): 52b4739

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -17
app.py CHANGED
@@ -39,23 +39,23 @@ def wait_for_image_with_prefix(folder, prefix):
39
  time.sleep(1)
40
  return initial_size == os.path.getsize(file_path)
41
 
42
- while True:
43
- files = os.listdir(folder)
44
- image_files = [f for f in files if f.lower().startswith(prefix.lower()) and
45
- f.lower().endswith(('.png', '.jpg', '.jpeg'))]
46
-
47
- if image_files:
48
- # Sort by modification time to get the latest file
49
- image_files.sort(key=lambda x: os.path.getmtime(os.path.join(folder, x)), reverse=True)
50
- latest_image = os.path.join(folder, image_files[0])
51
-
52
- if is_file_ready(latest_image):
53
- # Wait a bit more to ensure the file is completely written
54
- time.sleep(3)
55
- return latest_image
56
-
57
- # If no matching file found, wait before checking again
58
- time.sleep(1)
59
 
60
 
61
  def delete_image_file(file_path):
 
39
  time.sleep(1)
40
  return initial_size == os.path.getsize(file_path)
41
 
42
+
43
+ files = os.listdir(folder)
44
+ image_files = [f for f in files if f.lower().startswith(prefix.lower()) and
45
+ f.lower().endswith(('.png', '.jpg', '.jpeg'))]
46
+
47
+ if image_files:
48
+ # Sort by modification time to get the latest file
49
+ image_files.sort(key=lambda x: os.path.getmtime(os.path.join(folder, x)), reverse=True)
50
+ latest_image = os.path.join(folder, image_files[0])
51
+
52
+ if is_file_ready(latest_image):
53
+ # Wait a bit more to ensure the file is completely written
54
+ time.sleep(3)
55
+ return latest_image
56
+
57
+
58
+ return None
59
 
60
 
61
  def delete_image_file(file_path):