att
This commit is contained in:
parent
67aa7d311d
commit
76316a9237
@ -412,15 +412,33 @@ def main():
|
|||||||
end_time = time.time() + 180 # até 3 minutos
|
end_time = time.time() + 180 # até 3 minutos
|
||||||
downloaded_file = None
|
downloaded_file = None
|
||||||
while time.time() < end_time:
|
while time.time() < end_time:
|
||||||
# Esperar terminar downloads parciais
|
# Esperar terminar downloads parciais (.crdownload ou arquivos temporários do Chrome)
|
||||||
if any(name.endswith('.crdownload') for name in os.listdir(download_dir)):
|
current_dir_files = os.listdir(download_dir)
|
||||||
|
if any(name.endswith('.crdownload') for name in current_dir_files):
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
continue
|
continue
|
||||||
current_files = set(f for f in os.listdir(download_dir) if not f.endswith('.crdownload'))
|
|
||||||
|
# Filtrar arquivos válidos:
|
||||||
|
# - Não termina com .crdownload
|
||||||
|
# - Não começa com . (arquivos temporários/ocultos do Chrome)
|
||||||
|
# - Não contém .com.google.Chrome (arquivos temporários específicos)
|
||||||
|
def is_valid_file(filename):
|
||||||
|
if filename.endswith('.crdownload'):
|
||||||
|
return False
|
||||||
|
if filename.startswith('.'):
|
||||||
|
return False
|
||||||
|
if '.com.google.Chrome' in filename:
|
||||||
|
return False
|
||||||
|
return True
|
||||||
|
|
||||||
|
current_files = set(f for f in current_dir_files if is_valid_file(f))
|
||||||
new_files = [f for f in current_files - before_files]
|
new_files = [f for f in current_files - before_files]
|
||||||
|
|
||||||
if new_files:
|
if new_files:
|
||||||
# Escolher o mais recente
|
# Escolher o mais recente
|
||||||
candidate = max((os.path.join(download_dir, f) for f in new_files), key=os.path.getmtime)
|
candidate = max((os.path.join(download_dir, f) for f in new_files), key=os.path.getmtime)
|
||||||
|
# Verificar se o arquivo realmente existe e tem tamanho > 0
|
||||||
|
if os.path.exists(candidate) and os.path.getsize(candidate) > 0:
|
||||||
downloaded_file = candidate
|
downloaded_file = candidate
|
||||||
break
|
break
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
@ -685,14 +703,14 @@ def main():
|
|||||||
print("Script finalizado.")
|
print("Script finalizado.")
|
||||||
|
|
||||||
def run_with_retry(max_retries=3, retry_delay=120):
|
def run_with_retry(max_retries=3, retry_delay=120):
|
||||||
"""Executa main() com retentativas em caso de erro de timeout/conexão."""
|
"""Executa main() com retentativas em caso de erro de timeout/conexão/arquivo."""
|
||||||
for attempt in range(1, max_retries + 1):
|
for attempt in range(1, max_retries + 1):
|
||||||
try:
|
try:
|
||||||
main()
|
main()
|
||||||
return True # Sucesso
|
return True # Sucesso
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
error_str = str(e).lower()
|
error_str = str(e).lower()
|
||||||
# Verificar se é erro de timeout/conexão que vale retry
|
# Verificar se é erro de timeout/conexão/arquivo temporário que vale retry
|
||||||
is_retryable = any(keyword in error_str for keyword in [
|
is_retryable = any(keyword in error_str for keyword in [
|
||||||
'read timed out',
|
'read timed out',
|
||||||
'timed out',
|
'timed out',
|
||||||
@ -700,7 +718,10 @@ def run_with_retry(max_retries=3, retry_delay=120):
|
|||||||
'connectionpool',
|
'connectionpool',
|
||||||
'connection refused',
|
'connection refused',
|
||||||
'connection reset',
|
'connection reset',
|
||||||
'httpconnectionpool'
|
'httpconnectionpool',
|
||||||
|
'no such file or directory',
|
||||||
|
'.com.google.chrome',
|
||||||
|
'filenotfounderror'
|
||||||
])
|
])
|
||||||
|
|
||||||
if is_retryable and attempt < max_retries:
|
if is_retryable and attempt < max_retries:
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user