From 164de3859344a77cf027fcecf041ca6e13e69567 Mon Sep 17 00:00:00 2001 From: Stephan Akkerman Date: Sat, 10 Feb 2024 21:05:58 +0100 Subject: [PATCH] Improved temp images #close 476 --- src/cogs/loops/liquidations.py | 2 +- src/cogs/loops/rsi_heatmap.py | 2 +- src/cogs/loops/yield.py | 9 +++++---- src/main.py | 4 ++-- 4 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/cogs/loops/liquidations.py b/src/cogs/loops/liquidations.py index e3ee41bd..c2d35a45 100644 --- a/src/cogs/loops/liquidations.py +++ b/src/cogs/loops/liquidations.py @@ -151,7 +151,7 @@ async def post_liquidations(self): fig.set_size_inches(15, 6) # Convert to plot to a temporary image - filename = "liquidations.png" + filename = "temp/liquidations.png" plt.savefig(filename, bbox_inches="tight", dpi=300) plt.cla() plt.close() diff --git a/src/cogs/loops/rsi_heatmap.py b/src/cogs/loops/rsi_heatmap.py index 4054385b..100a77ef 100644 --- a/src/cogs/loops/rsi_heatmap.py +++ b/src/cogs/loops/rsi_heatmap.py @@ -143,7 +143,7 @@ async def post_rsi_heatmap(self): # Display the plot plt.tight_layout() - filename = "rsi_heatmap.png" + filename = "temp/rsi_heatmap.png" plt.savefig(filename, bbox_inches="tight", dpi=300) plt.cla() plt.close() diff --git a/src/cogs/loops/yield.py b/src/cogs/loops/yield.py index d48dc45b..64396625 100644 --- a/src/cogs/loops/yield.py +++ b/src/cogs/loops/yield.py @@ -74,7 +74,8 @@ async def post_curve(self) -> None: plt.xlabel("Residual Maturity") # Convert to plot to a temporary image - plt.savefig("yield.png", bbox_inches="tight", dpi=300) + file_name = "temp/yield.png" + plt.savefig(file_name, bbox_inches="tight", dpi=300) plt.cla() plt.close() @@ -84,14 +85,14 @@ async def post_curve(self) -> None: color=0x000000, timestamp=datetime.datetime.now(datetime.timezone.utc), ) - file = discord.File("yield.png") - e.set_image(url="attachment://yield.png") + file = discord.File(file_name) + e.set_image(url=f"attachment://{file_name}") await self.channel.purge(limit=1) await self.channel.send(file=file, embed=e) # Delete yield.png - os.remove("yield.png") + os.remove(file_name) async def plot_US_yield(self) -> None: """ diff --git a/src/main.py b/src/main.py index 8a3916b0..7a67e024 100644 --- a/src/main.py +++ b/src/main.py @@ -106,8 +106,8 @@ def load_folder(foldername: str) -> None: bot.load_extension("util.db") # Ensure the logs directory exists - if not os.path.exists("logs"): - os.makedirs("logs") + os.makedirs("logs", exist_ok=True) + os.makedirs("temp", exist_ok=True) # Load commands load_folder("commands")