Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -63,14 +63,35 @@ def archive_now(website):
|
|
| 63 |
|
| 64 |
archive_url = f"https://web.archive.org/save/{website}"
|
| 65 |
try:
|
| 66 |
-
response = requests.get(archive_url, headers=headers)
|
| 67 |
if response.status_code == 200:
|
| 68 |
return f"<div>👌 URL archivada con éxito en: <a href='https://web.archive.org/save/{website}' target='_blank'>https://web.archive.org/save/{website}</a></div>"
|
| 69 |
else:
|
| 70 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 71 |
except Exception as e:
|
| 72 |
return f"<div>Error al archivar la URL: {e}</div>"
|
| 73 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 74 |
|
| 75 |
# Crear la interfaz de Gradio para la función wayback
|
| 76 |
wayback_interface = gr.Interface(
|
|
|
|
| 63 |
|
| 64 |
archive_url = f"https://web.archive.org/save/{website}"
|
| 65 |
try:
|
| 66 |
+
response = requests.get(archive_url, headers=headers, timeout=60) # Establece un tiempo límite de 60 segundos
|
| 67 |
if response.status_code == 200:
|
| 68 |
return f"<div>👌 URL archivada con éxito en: <a href='https://web.archive.org/save/{website}' target='_blank'>https://web.archive.org/save/{website}</a></div>"
|
| 69 |
else:
|
| 70 |
+
# Si la respuesta no es exitosa, busca la última instantánea
|
| 71 |
+
return check_last_snapshot(website)
|
| 72 |
+
except requests.exceptions.Timeout:
|
| 73 |
+
# Si se supera el tiempo de espera, busca la última instantánea
|
| 74 |
+
return check_last_snapshot(website)
|
| 75 |
except Exception as e:
|
| 76 |
return f"<div>Error al archivar la URL: {e}</div>"
|
| 77 |
|
| 78 |
+
def check_last_snapshot(website):
|
| 79 |
+
availability_api_url = f"http://archive.org/wayback/available?url={website}"
|
| 80 |
+
try:
|
| 81 |
+
response = requests.get(availability_api_url, headers=headers)
|
| 82 |
+
if response.status_code == 200:
|
| 83 |
+
data = json.loads(response.text)
|
| 84 |
+
if data["archived_snapshots"]:
|
| 85 |
+
closest_snapshot = data["archived_snapshots"]["closest"]
|
| 86 |
+
if closest_snapshot and closest_snapshot["available"]:
|
| 87 |
+
snapshot_url = closest_snapshot["url"]
|
| 88 |
+
timestamp = closest_snapshot["timestamp"]
|
| 89 |
+
formatted_date = datetime.strptime(timestamp, '%Y%m%d%H%M%S').strftime('%d/%m/%Y')
|
| 90 |
+
return f"<div>Última instantánea disponible: <a href='{snapshot_url}' target='_blank'>{formatted_date}</a></div>"
|
| 91 |
+
except Exception as e:
|
| 92 |
+
return f"<div>Error al buscar la última instantánea: {e}</div>"
|
| 93 |
+
return "<div>😭 No se encontraron datos archivados para esta URL.</div>"
|
| 94 |
+
|
| 95 |
|
| 96 |
# Crear la interfaz de Gradio para la función wayback
|
| 97 |
wayback_interface = gr.Interface(
|