Spaces:
Sleeping
Sleeping
cha0smagick
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -2,65 +2,53 @@ import streamlit as st
|
|
2 |
import requests
|
3 |
import pandas as pd
|
4 |
import matplotlib.pyplot as plt
|
5 |
-
import time
|
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 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
ax.set_title('Volumen de las Top 25 Criptomonedas')
|
57 |
-
ax.grid(True)
|
58 |
-
plt.xticks(rotation=45)
|
59 |
-
st.pyplot(fig)
|
60 |
-
else:
|
61 |
-
st.error("No se pudieron obtener los datos.")
|
62 |
-
|
63 |
-
st.write("Presiona el bot贸n en el men煤 lateral para actualizar los datos.")
|
64 |
-
|
65 |
-
if __name__ == "__main__":
|
66 |
-
main()
|
|
|
2 |
import requests
|
3 |
import pandas as pd
|
4 |
import matplotlib.pyplot as plt
|
|
|
5 |
|
6 |
+
# Lista de criptomonedas
|
7 |
+
cryptos = [
|
8 |
+
"BTC", "ETH", "USDT", "BNB", "XRP", "ADA", "DOGE", "SOL", "DOT",
|
9 |
+
"USDC", "LTC", "LINK", "MATIC", "AVAX", "XLM", "BCH", "SHIB",
|
10 |
+
"UNI", "ATOM", "ALGO", "VET", "XMR", "FIL", "TRX", "XTZ",
|
11 |
+
"AAVE", "HBAR", "ICP", "EGLD", "THETA"
|
12 |
+
]
|
13 |
+
|
14 |
+
# Funci贸n para obtener datos de la API
|
15 |
+
def get_crypto_data():
|
16 |
+
url = "https://api.minerstat.com/v2/coins"
|
17 |
+
params = {
|
18 |
+
'list': ','.join(cryptos)
|
19 |
+
}
|
20 |
+
headers = {
|
21 |
+
'x-rapidapi-host': 'coingecko.p.rapidapi.com',
|
22 |
+
'x-rapidapi-key': 'c4b66a3c25msh950412fab4eaee1p159dbfjsn4'
|
23 |
+
}
|
24 |
+
|
25 |
+
response = requests.get(url, headers=headers, params=params)
|
26 |
+
return response.json()
|
27 |
+
|
28 |
+
# Inicializar la aplicaci贸n
|
29 |
+
st.title("Estad铆sticas de Criptomonedas")
|
30 |
+
st.markdown("Esta aplicaci贸n muestra las estad铆sticas de las 30 criptomonedas m谩s populares.")
|
31 |
+
|
32 |
+
# Bot贸n para actualizar datos
|
33 |
+
if st.button("Actualizar datos"):
|
34 |
+
data = get_crypto_data()
|
35 |
+
df = pd.DataFrame(data)
|
36 |
+
|
37 |
+
# Mostrar datos en una tabla
|
38 |
+
st.subheader("Estad铆sticas de las Criptomonedas")
|
39 |
+
st.dataframe(df[['coin', 'name', 'price', 'volume', 'algorithm', 'difficulty', 'reward_block']])
|
40 |
+
|
41 |
+
# Gr谩fica de precios
|
42 |
+
st.subheader("Fluctuaci贸n de Precios")
|
43 |
+
prices = df['price'].astype(float)
|
44 |
+
plt.figure(figsize=(10, 5))
|
45 |
+
plt.plot(prices, marker='o')
|
46 |
+
plt.title('Fluctuaci贸n de Precios de Criptomonedas')
|
47 |
+
plt.xticks(range(len(cryptos)), cryptos)
|
48 |
+
plt.xlabel('Criptomonedas')
|
49 |
+
plt.ylabel('Precio en USD')
|
50 |
+
plt.grid()
|
51 |
+
st.pyplot(plt)
|
52 |
+
|
53 |
+
else:
|
54 |
+
st.write("Presiona el bot贸n para actualizar los datos.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|