Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,31 +3,45 @@ 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 |
# Webhook Discord
|
| 11 |
DISCORD_WEBHOOK_URL = "https://discord.com/api/webhooks/1300875245913247900/FNoZf15Lhn_QDljoJN8NLB1MTUTJ3QYtnkh4sNt_C-VmHf2P1kq2v77ZOxAkGPj_Amsm"
|
| 12 |
|
|
|
|
| 13 |
def get_crypto_prices():
|
| 14 |
-
end_time =
|
| 15 |
-
start_time = end_time - 48
|
| 16 |
-
coins =
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
prices = {}
|
| 18 |
|
| 19 |
-
for coin in coins:
|
| 20 |
-
url = f'https://api.
|
| 21 |
-
params = {
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
response = requests.get(url, params=params)
|
| 23 |
if response.status_code == 200:
|
| 24 |
-
|
| 25 |
-
prices[coin]
|
|
|
|
|
|
|
|
|
|
| 26 |
else:
|
| 27 |
st.error(f"Erreur lors de la récupération des prix pour {coin}: {response.status_code}")
|
| 28 |
|
| 29 |
return prices
|
| 30 |
|
|
|
|
| 31 |
def create_graph(prices_history):
|
| 32 |
fig, axs = plt.subplots(nrows=2, ncols=2, figsize=(15, 10))
|
| 33 |
axs = axs.flatten()
|
|
@@ -51,6 +65,7 @@ def create_graph(prices_history):
|
|
| 51 |
plt.savefig('crypto_prices_rectangle.png')
|
| 52 |
plt.close()
|
| 53 |
|
|
|
|
| 54 |
def send_to_discord(prices, image_path):
|
| 55 |
embed = {
|
| 56 |
"content": "Mise à jour des prix des crypto-monnaies",
|
|
|
|
| 3 |
import matplotlib.dates as mdates
|
| 4 |
import os
|
| 5 |
import time
|
| 6 |
+
from datetime import datetime, timedelta
|
| 7 |
import numpy as np
|
| 8 |
import streamlit as st
|
| 9 |
|
| 10 |
# Webhook Discord
|
| 11 |
DISCORD_WEBHOOK_URL = "https://discord.com/api/webhooks/1300875245913247900/FNoZf15Lhn_QDljoJN8NLB1MTUTJ3QYtnkh4sNt_C-VmHf2P1kq2v77ZOxAkGPj_Amsm"
|
| 12 |
|
| 13 |
+
# Récupérer les prix des crypto-monnaies via l'API CoinCap
|
| 14 |
def get_crypto_prices():
|
| 15 |
+
end_time = datetime.utcnow()
|
| 16 |
+
start_time = end_time - timedelta(hours=48)
|
| 17 |
+
coins = {
|
| 18 |
+
'bitcoin': 'bitcoin',
|
| 19 |
+
'ethereum': 'ethereum',
|
| 20 |
+
'tether': 'tether',
|
| 21 |
+
'ripple': 'xrp'
|
| 22 |
+
}
|
| 23 |
prices = {}
|
| 24 |
|
| 25 |
+
for coin, coin_id in coins.items():
|
| 26 |
+
url = f'https://api.coincap.io/v2/assets/{coin_id}/history'
|
| 27 |
+
params = {
|
| 28 |
+
'interval': 'm15',
|
| 29 |
+
'start': int(start_time.timestamp() * 1000),
|
| 30 |
+
'end': int(end_time.timestamp() * 1000)
|
| 31 |
+
}
|
| 32 |
response = requests.get(url, params=params)
|
| 33 |
if response.status_code == 200:
|
| 34 |
+
data = response.json().get('data', [])
|
| 35 |
+
prices[coin] = [[int(item['time']), float(item['priceUsd'])] for item in data]
|
| 36 |
+
# Ajouter l'heure actuelle avec le dernier prix pour chaque crypto
|
| 37 |
+
if data:
|
| 38 |
+
prices[coin].append([int(end_time.timestamp() * 1000), float(data[-1]['priceUsd'])])
|
| 39 |
else:
|
| 40 |
st.error(f"Erreur lors de la récupération des prix pour {coin}: {response.status_code}")
|
| 41 |
|
| 42 |
return prices
|
| 43 |
|
| 44 |
+
# Créer un graphique rectangulaire
|
| 45 |
def create_graph(prices_history):
|
| 46 |
fig, axs = plt.subplots(nrows=2, ncols=2, figsize=(15, 10))
|
| 47 |
axs = axs.flatten()
|
|
|
|
| 65 |
plt.savefig('crypto_prices_rectangle.png')
|
| 66 |
plt.close()
|
| 67 |
|
| 68 |
+
# Envoyer les prix à Discord
|
| 69 |
def send_to_discord(prices, image_path):
|
| 70 |
embed = {
|
| 71 |
"content": "Mise à jour des prix des crypto-monnaies",
|