Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,6 +3,11 @@ from datetime import datetime, timedelta
|
|
| 3 |
import requests
|
| 4 |
import json
|
| 5 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
def wayback(website):
|
| 7 |
if not website:
|
| 8 |
return '<p>😭 Error: introduce una url correcta</p>'
|
|
@@ -15,7 +20,7 @@ def wayback(website):
|
|
| 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:
|
|
@@ -37,7 +42,7 @@ def wayback(website):
|
|
| 37 |
# Si falla, intentar con la Wayback Availability JSON API
|
| 38 |
availability_api_url = f"http://archive.org/wayback/available?url={website}"
|
| 39 |
try:
|
| 40 |
-
response = requests.get(availability_api_url)
|
| 41 |
if response.status_code == 200:
|
| 42 |
data = json.loads(response.text)
|
| 43 |
if data["archived_snapshots"]:
|
|
@@ -58,7 +63,7 @@ def archive_now(website):
|
|
| 58 |
|
| 59 |
archive_url = f"https://web.archive.org/save/{website}"
|
| 60 |
try:
|
| 61 |
-
response = requests.get(archive_url)
|
| 62 |
if response.status_code == 200:
|
| 63 |
return f"URL archivada con éxito: {archive_url}"
|
| 64 |
else:
|
|
|
|
| 3 |
import requests
|
| 4 |
import json
|
| 5 |
|
| 6 |
+
# Define los headers para simular una petición desde Firefox
|
| 7 |
+
headers = {
|
| 8 |
+
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:71.0) Gecko/20100101 Firefox/71.0'
|
| 9 |
+
}
|
| 10 |
+
|
| 11 |
def wayback(website):
|
| 12 |
if not website:
|
| 13 |
return '<p>😭 Error: introduce una url correcta</p>'
|
|
|
|
| 20 |
cdx_api_url = f"http://web.archive.org/cdx/search/cdx?url={website}&output=json&from={datefrom}&to={dateto}&limit=3000"
|
| 21 |
|
| 22 |
try:
|
| 23 |
+
response = requests.get(cdx_api_url, headers=headers)
|
| 24 |
if response.status_code == 200:
|
| 25 |
content = json.loads(response.text)
|
| 26 |
if len(content) > 1:
|
|
|
|
| 42 |
# Si falla, intentar con la Wayback Availability JSON API
|
| 43 |
availability_api_url = f"http://archive.org/wayback/available?url={website}"
|
| 44 |
try:
|
| 45 |
+
response = requests.get(availability_api_url, headers=headers)
|
| 46 |
if response.status_code == 200:
|
| 47 |
data = json.loads(response.text)
|
| 48 |
if data["archived_snapshots"]:
|
|
|
|
| 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"URL archivada con éxito: {archive_url}"
|
| 69 |
else:
|