Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,16 +2,15 @@ import requests
|
|
| 2 |
import matplotlib.pyplot as plt
|
| 3 |
import matplotlib.dates as mdates
|
| 4 |
import os
|
|
|
|
| 5 |
from datetime import datetime
|
| 6 |
import numpy as np
|
| 7 |
import streamlit as st
|
| 8 |
|
| 9 |
-
|
| 10 |
-
DISCORD_WEBHOOK_URL = os.getenv('https://discord.com/api/webhooks/1300875245913247900/FNoZf15Lhn_QDljoJN8NLB1MTUTJ3QYtnkh4sNt_C-VmHf2P1kq2v77ZOxAkGPj_Amsm')
|
| 11 |
if DISCORD_WEBHOOK_URL is None:
|
| 12 |
st.error("La variable d'environnement 'DISCORD_WEBHOOK_URL' n'est pas définie.")
|
| 13 |
|
| 14 |
-
# Récupérer les prix des crypto-monnaies
|
| 15 |
def get_crypto_prices():
|
| 16 |
end_time = int(time.time())
|
| 17 |
start_time = end_time - 48 * 3600
|
|
@@ -24,13 +23,12 @@ def get_crypto_prices():
|
|
| 24 |
response = requests.get(url, params=params)
|
| 25 |
if response.status_code == 200:
|
| 26 |
prices[coin] = response.json().get('prices', [])
|
| 27 |
-
prices[coin].append([end_time * 1000, prices[coin][-1][1]])
|
| 28 |
else:
|
| 29 |
st.error(f"Erreur lors de la récupération des prix pour {coin}: {response.status_code}")
|
| 30 |
|
| 31 |
return prices
|
| 32 |
|
| 33 |
-
# Créer un graphique rectangulaire
|
| 34 |
def create_graph(prices_history):
|
| 35 |
fig, axs = plt.subplots(nrows=2, ncols=2, figsize=(15, 10))
|
| 36 |
axs = axs.flatten()
|
|
@@ -54,7 +52,6 @@ def create_graph(prices_history):
|
|
| 54 |
plt.savefig('crypto_prices_rectangle.png')
|
| 55 |
plt.close()
|
| 56 |
|
| 57 |
-
# Envoyer à Discord
|
| 58 |
def send_to_discord(prices, image_path):
|
| 59 |
embed = {
|
| 60 |
"content": "Mise à jour des prix des crypto-monnaies",
|
|
@@ -67,15 +64,14 @@ def send_to_discord(prices, image_path):
|
|
| 67 |
with open(image_path, 'rb') as f:
|
| 68 |
requests.post(DISCORD_WEBHOOK_URL, json=embed, files={"file": (image_path, f)})
|
| 69 |
|
| 70 |
-
|
| 71 |
-
st.
|
| 72 |
-
|
| 73 |
-
if st.button("Mettre à jour les prix"):
|
| 74 |
prices = get_crypto_prices()
|
| 75 |
-
st.
|
| 76 |
|
| 77 |
prices_history = {coin: prices.get(coin, []) for coin in ['bitcoin', 'ethereum', 'tether', 'ripple']}
|
| 78 |
create_graph(prices_history)
|
|
|
|
| 79 |
|
| 80 |
st.image('crypto_prices_rectangle.png')
|
| 81 |
-
|
|
|
|
| 2 |
import matplotlib.pyplot as plt
|
| 3 |
import matplotlib.dates as mdates
|
| 4 |
import os
|
| 5 |
+
import time
|
| 6 |
from datetime import datetime
|
| 7 |
import numpy as np
|
| 8 |
import streamlit as st
|
| 9 |
|
| 10 |
+
DISCORD_WEBHOOK_URL = os.getenv('DISCORD_WEBHOOK_URL')
|
|
|
|
| 11 |
if DISCORD_WEBHOOK_URL is None:
|
| 12 |
st.error("La variable d'environnement 'DISCORD_WEBHOOK_URL' n'est pas définie.")
|
| 13 |
|
|
|
|
| 14 |
def get_crypto_prices():
|
| 15 |
end_time = int(time.time())
|
| 16 |
start_time = end_time - 48 * 3600
|
|
|
|
| 23 |
response = requests.get(url, params=params)
|
| 24 |
if response.status_code == 200:
|
| 25 |
prices[coin] = response.json().get('prices', [])
|
| 26 |
+
prices[coin].append([end_time * 1000, prices[coin][-1][1]])
|
| 27 |
else:
|
| 28 |
st.error(f"Erreur lors de la récupération des prix pour {coin}: {response.status_code}")
|
| 29 |
|
| 30 |
return prices
|
| 31 |
|
|
|
|
| 32 |
def create_graph(prices_history):
|
| 33 |
fig, axs = plt.subplots(nrows=2, ncols=2, figsize=(15, 10))
|
| 34 |
axs = axs.flatten()
|
|
|
|
| 52 |
plt.savefig('crypto_prices_rectangle.png')
|
| 53 |
plt.close()
|
| 54 |
|
|
|
|
| 55 |
def send_to_discord(prices, image_path):
|
| 56 |
embed = {
|
| 57 |
"content": "Mise à jour des prix des crypto-monnaies",
|
|
|
|
| 64 |
with open(image_path, 'rb') as f:
|
| 65 |
requests.post(DISCORD_WEBHOOK_URL, json=embed, files={"file": (image_path, f)})
|
| 66 |
|
| 67 |
+
st.title("Suivi des Prix des Cryptomonnaies")
|
| 68 |
+
if st.button("Exécuter"):
|
|
|
|
|
|
|
| 69 |
prices = get_crypto_prices()
|
| 70 |
+
st.write(f"Prix récupérés: {prices}")
|
| 71 |
|
| 72 |
prices_history = {coin: prices.get(coin, []) for coin in ['bitcoin', 'ethereum', 'tether', 'ripple']}
|
| 73 |
create_graph(prices_history)
|
| 74 |
+
send_to_discord(prices, 'crypto_prices_rectangle.png')
|
| 75 |
|
| 76 |
st.image('crypto_prices_rectangle.png')
|
| 77 |
+
st.success("Graphique créé et envoyé à Discord!")
|