tx3bas commited on
Commit
84c7ded
·
verified ·
1 Parent(s): 7d90634

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +40 -0
app.py ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from datetime import datetime, timedelta
3
+ import requests
4
+ import json
5
+
6
+ def wayback(website, limit=3000):
7
+ if not website:
8
+ return '😭 Error: introduce una url correcta'
9
+
10
+ end_date = datetime.now()
11
+ start_date = end_date - timedelta(days=365)
12
+ datefrom = start_date.strftime('%Y%m%d')
13
+ dateto = end_date.strftime('%Y%m%d')
14
+
15
+ query = f"?url={website}&output=json&from={datefrom}&to={dateto}"
16
+
17
+ try:
18
+ response = requests.get(f"http://web.archive.org/cdx/search/cdx{query}&limit={limit}")
19
+ content = json.loads(response.text)[1:]
20
+ except Exception as e:
21
+ return f"😭 Error: {e}"
22
+
23
+ if len(content) > 0:
24
+ results = []
25
+ for row in content:
26
+ date, page, status = [row[i] for i in [1, 2, 4]]
27
+ formatted_date = datetime.strptime(date, '%Y%m%d%H%M%S').strftime('%d/%m/%Y')
28
+ formatted_wayback_url = f"https://web.archive.org/web/{date}/{page}"
29
+ results.append(f"👓 {formatted_date} {formatted_wayback_url}")
30
+ return "\n".join(results)
31
+ else:
32
+ return '😭 Error: no hay datos para esta página web'
33
+
34
+ iface = gr.Interface(fn=wayback,
35
+ inputs=["text", gr.Number(label="Límite", default=3000, optional=True)],
36
+ outputs="text",
37
+ title="Wayback Machine Lookup",
38
+ description="Busca instantáneas de una página web en la Wayback Machine.")
39
+
40
+ iface.launch()