tx3bas commited on
Commit
0160296
·
verified ·
1 Parent(s): 65032aa

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -35
app.py CHANGED
@@ -5,47 +5,20 @@ import json
5
 
6
  def wayback(website):
7
  if not website:
8
- return '<p>😭 Error: introduce una url correcta</p>'
9
- # Estilos CSS para la tabla
10
- style = """
11
- <style>
12
- table {
13
- width: 100%;
14
- border-collapse: collapse;
15
- }
16
- th, td {
17
- border: 1px solid #dddddd;
18
- text-align: left;
19
- padding: 8px;
20
- }
21
- th {
22
- background-color: #f2f2f2;
23
- }
24
- tr:nth-child(even) {
25
- background-color: #f9f9f9;
26
- }
27
- a {
28
- color: #0645ad;
29
- text-decoration: none;
30
- }
31
- a:hover {
32
- text-decoration: underline;
33
- }
34
- </style>
35
- """
36
- # Intentar primero con la Wayback CDX Server API
37
  end_date = datetime.now()
38
- start_date = end_date - timedelta(days=1095)
39
  datefrom = start_date.strftime('%Y%m%d')
40
  dateto = end_date.strftime('%Y%m%d')
41
- cdx_api_url = f"http://web.archive.org/cdx/search/cdx?url={website}&output=json&from={datefrom}&to={dateto}&limit=9000"
42
 
43
  try:
44
  response = requests.get(cdx_api_url)
45
  if response.status_code == 200:
46
  content = json.loads(response.text)
47
  if len(content) > 1:
48
- # Procesar y mostrar los resultados
49
  results = []
50
  for row in content[1:]:
51
  date, page, status = [row[i] for i in [1, 2, 4]]
@@ -53,8 +26,8 @@ def wayback(website):
53
  formatted_wayback_url = f"https://web.archive.org/web/{date}/{page}"
54
  results.append({'date': date, 'formatted_date': formatted_date, 'link': formatted_wayback_url})
55
  results.sort(key=lambda x: x['date'], reverse=True)
56
- formatted_results = [f"<tr><td>{item['formatted_date']}</td><td><a href='{item['link']}' target='_blank'>{item['link']}</a></td></tr>" for item in results]
57
- return "<table><tr><th>Fecha</th><th>URL</th></tr>" + "".join(formatted_results) + "</table>"
58
  except Exception as e:
59
  pass # Falla silenciosa, intentar con el siguiente método
60
 
@@ -70,7 +43,7 @@ def wayback(website):
70
  snapshot_url = closest_snapshot["url"]
71
  timestamp = closest_snapshot["timestamp"]
72
  formatted_date = datetime.strptime(timestamp, '%Y%m%d%H%M%S').strftime('%d/%m/%Y')
73
- return f'<table><tr><th>Fecha</th><th>URL</th></tr><tr><td>{formatted_date}</td><td><a href="{snapshot_url}" target="_blank">{snapshot_url}</a></td></tr></table>'
74
  except Exception as e:
75
  return f"<p>😭 Error: {e}</p>"
76
 
 
5
 
6
  def wayback(website):
7
  if not website:
8
+ return '😭 Error: introduce una url correcta'
9
+
10
+ # Intenta primero con la Wayback CDX Server API
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
11
  end_date = datetime.now()
12
+ start_date = end_date - timedelta(days=365)
13
  datefrom = start_date.strftime('%Y%m%d')
14
  dateto = end_date.strftime('%Y%m%d')
15
+ cdx_api_url = f"http://web.archive.org/cdx/search/cdx?url={website}&output=json&from={datefrom}&to={dateto}&limit=3000"
16
 
17
  try:
18
  response = requests.get(cdx_api_url)
19
  if response.status_code == 200:
20
  content = json.loads(response.text)
21
  if len(content) > 1:
 
22
  results = []
23
  for row in content[1:]:
24
  date, page, status = [row[i] for i in [1, 2, 4]]
 
26
  formatted_wayback_url = f"https://web.archive.org/web/{date}/{page}"
27
  results.append({'date': date, 'formatted_date': formatted_date, 'link': formatted_wayback_url})
28
  results.sort(key=lambda x: x['date'], reverse=True)
29
+ formatted_results = [f"👓 {item['formatted_date']} <a href='{item['link']}' target='_blank'>{item['link']}</a>" for item in results]
30
+ return "<br>".join(formatted_results)
31
  except Exception as e:
32
  pass # Falla silenciosa, intentar con el siguiente método
33
 
 
43
  snapshot_url = closest_snapshot["url"]
44
  timestamp = closest_snapshot["timestamp"]
45
  formatted_date = datetime.strptime(timestamp, '%Y%m%d%H%M%S').strftime('%d/%m/%Y')
46
+ return f"👓 Instantánea más reciente: {formatted_date} <a href='{snapshot_url}' target='_blank'>{snapshot_url}</a>"
47
  except Exception as e:
48
  return f"<p>😭 Error: {e}</p>"
49