Download app.py from Yofran23/monitor: direct link, hf CLI and curl.
- Browser
- Download file 2.57 kB
-
https://huggingface.co/spaces/Yofran23/monitor/resolve/main/app.py
- Command line
-
hf download hf://spaces/Yofran23/monitor/app.py
-
curl -L -o app.py https://huggingface.co/spaces/Yofran23/monitor/resolve/main/app.py
2.57 kB
| import streamlit as st | |
| import requests | |
| import pandas as pd | |
| from bs4 import BeautifulSoup | |
| import urllib3 | |
| # Configuraci贸n de p谩gina | |
| st.set_page_config(page_title="Monitor Cambiario", page_icon="馃搱", layout="centered") | |
| # Deshabilitar advertencias de SSL (equivalente a ssl_verifypeer = FALSE en R) | |
| urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning) | |
| def get_data(): | |
| # --- API BINANCE (v铆a CriptoYa) --- | |
| try: | |
| url_crypto = "https://criptoya.com/api/USDT/VES/0.1" | |
| res_crypto = requests.get(url_crypto) | |
| data_crypto = res_crypto.json() | |
| usdt_price = data_crypto['binancep2p']['totalAsk'] | |
| except: | |
| usdt_price = 0 | |
| # --- SCRAPING BCV --- | |
| try: | |
| url_bcv = "https://www.bcv.org.ve" | |
| # User-agent para evitar bloqueos | |
| headers = {'User-Agent': 'Mozilla/5.0'} | |
| res_bcv = requests.get(url_bcv, headers=headers, verify=False) | |
| soup = BeautifulSoup(res_bcv.text, 'html.parser') | |
| # Extracci贸n siguiendo tu l贸gica de IDs | |
| dolar = float(soup.find(id="dolar").find("strong").text.strip().replace(',', '.')) | |
| euro = float(soup.find(id="euro").find("strong").text.strip().replace(',', '.')) | |
| except: | |
| dolar, euro = 0, 0 | |
| return usdt_price, dolar, euro | |
| # --- INTERFAZ STREAMLIT --- | |
| st.title("馃搳 Monitor de Divisas") | |
| st.markdown(f"**脷ltima actualizaci贸n:** {pd.Timestamp.now().strftime('%d/%m/%Y %H:%M:%S')}") | |
| usdt, usd_bcv, eur_bcv = get_data() | |
| # M茅tricas principales en columnas est茅ticas | |
| col1, col2, col3 = st.columns(3) | |
| with col1: | |
| st.metric(label="USDT (Binance)", value=f"{usdt:.2f} VES") | |
| with col2: | |
| st.metric(label="D贸lar BCV", value=f"{usd_bcv:.2f} VES") | |
| with col3: | |
| st.metric(label="Euro BCV", value=f"{eur_bcv:.2f} VES") | |
| st.divider() | |
| # --- SECCI脫N DE C脕LCULOS --- | |
| st.subheader("馃挕 An谩lisis de Compra") | |
| # Tu l贸gica: Comprar d贸lar con 10% de descuento sobre el USDT | |
| compra_sugerida = usdt - (usdt * 0.10) | |
| c1, c2 = st.columns(2) | |
| with c1: | |
| st.info(f"**Precio USDT:** {usdt:.2f}") | |
| st.success(f"**Sugerencia de compra (-10%):** {compra_sugerida:.2f} VES") | |
| with c2: | |
| # Brecha entre paralelo (USDT) y oficial | |
| brecha = ((usdt / usd_bcv) - 1) * 100 if usd_bcv > 0 else 0 | |
| st.warning(f"**Brecha Cambiaria:** {brecha:.2f}%") | |
| # --- TABLA RESUMEN --- | |
| st.subheader("馃摑 Resumen de Datos") | |
| df_mostrar = pd.DataFrame({ | |
| "Moneda": ["USDT", "BCV $", "BCV Euro"], | |
| "Monto (VES)": [usdt, usd_bcv, eur_bcv] | |
| }) | |
| st.table(df_mostrar) | |
| if st.button('馃攧 Actualizar Precios'): | |
| st.rerun() | |