-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
39 lines (30 loc) · 1.34 KB
/
Copy pathmain.py
File metadata and controls
39 lines (30 loc) · 1.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
from flask import Flask, jsonify
app = Flask(__name__)
from flask import Flask, jsonify
import requests
app = Flask(__name__)
@app.route('/bcv', methods=['GET'])
def bcv_scraper():
try:
print("Inicio del scraping BCV")
response = requests.get("https://www.bcv.org.ve", timeout=10)
response.raise_for_status() # Lanza excepción si el status no es 200
# Aquí deberías extraer las tasas del HTML
# Simulación de datos extraídos:
tasas = {
"usd": "38.50",
"eur": "41.20"
}
print("Scraping exitoso")
return jsonify(tasas)
except requests.exceptions.Timeout:
print("Timeout al conectar con BCV")
return jsonify({"status": "error", "data": {"error_id": "408", "message": "Tiempo de espera agotado"}}), 408
except requests.exceptions.RequestException as e:
print("Error de conexión:", str(e))
return jsonify({"status": "error", "data": {"error_id": "500", "message": "Error de conexión", "detalle": str(e)}}), 500
except Exception as e:
print("Error interno:", str(e))
return jsonify({"status": "error", "data": {"error_id": "500", "message": "Error interno", "detalle": str(e)}}), 500
if __name__ == '__main__':
app.run(host='0.0.0.0', port=5000, debug=True)