From 03ba417b7f22949e68091e15738d6623fdd16664 Mon Sep 17 00:00:00 2001 From: NikolajDanger Date: Mon, 1 Feb 2021 23:42:58 +0100 Subject: [PATCH] :rewind: --- cogs/MiscCog.py | 5 --- funcs/other/bedreNetflix.py | 66 +------------------------------------ 2 files changed, 1 insertion(+), 70 deletions(-) diff --git a/cogs/MiscCog.py b/cogs/MiscCog.py index 4fe8746..5fb7265 100644 --- a/cogs/MiscCog.py +++ b/cogs/MiscCog.py @@ -136,11 +136,6 @@ class MiscCog(commands.Cog): async def downloading(self,ctx): await self.bedreNetflix.downloading(ctx) - #Calculates how much space is used on the server - @commands.command(aliases = ["dirsize","storage"]) - async def directorySizes(self,ctx): - await self.bedreNetflix.directorySizes(ctx) - #Looks up on Wolfram Alpha @commands.command() async def wolf(self, ctx, *, content): diff --git a/funcs/other/bedreNetflix.py b/funcs/other/bedreNetflix.py index f78b712..8d10f74 100644 --- a/funcs/other/bedreNetflix.py +++ b/funcs/other/bedreNetflix.py @@ -1,4 +1,4 @@ -import requests, imdb, discord, json, math, time, asyncio, os, concurrent.futures +import requests, imdb, discord, json, math, time, asyncio from funcs import logThis radarrURL = "http://localhost:7878/api/v3/" @@ -7,32 +7,6 @@ qbittorrentURL = "http://localhost:1340/api/v2/" moviePath = "/media/plex/Server/movies/" showPath = "/media/plex/Server/Shows/" -def getSize(startPath,pathLength): - logThis("Getting the size of "+startPath) - totalSize = 0 - for dirpath, dirnames, filenames in os.walk(startPath): - for f in filenames: - fp = os.path.join(dirpath, f) - # skip if it is symbolic link - if not os.path.islink(fp): - print(fp[:60],end="\r") - totalSize += os.path.getsize(fp) - - return totalSize - - -async def formatSize(size): - if size >= 1024**4: - return ("%.1f" % (size/(1024**4))) + "TB" - elif size >= 1024**3: - return ("%.1f" % (size/(1024**3))) + "GB" - elif size >= 1024**2: - return ("%.1f" % (size/(1024**2))) + "MB" - elif size >= 1024: - return ("%.1f" % (size/(1024))) + "KB" - else: - return str(size)+"b" - class BedreNetflix(): def __init__(self,bot): self.bot = bot @@ -276,41 +250,3 @@ class BedreNetflix(): else: await ctx.send(messageText) - async def directorySizes(self,ctx): - logThis("Calculating directory size") - message = await ctx.send("```Calculating directory size. This might take a while.```") - startPath = ".." - pathLength = len(startPath) - directories = [] - for f in os.listdir(startPath): - fp = os.path.join(startPath, f) - if os.path.isfile(fp): - size = os.path.getsize(fp) - else: - with concurrent.futures.ThreadPoolExecutor() as executor: - future = executor.submit(getSize,fp,pathLength) - size = future.result() - directories.append((str(f),size)) - directories.sort(key=lambda tup: tup[1]) - directories.reverse() - returnText = "```Calculating directory size. This might take a while.\n" - total = 0 - for directory, size in directories: - total += size - sizeText = await formatSize(size) - returnText += "\n"+directory+": "+sizeText - returnText += "\nTotal: "+await formatSize(total)+"```" - await message.edit(content=returnText) - - directories.sort(key=lambda tup: tup[1]) - directories.reverse() - returnText = "```" - total = 0 - for directory, size in directories: - total += size - sizeText = await formatSize(size) - returnText += "\n"+directory+": "+sizeText - returnText += "\nTotal: "+await formatSize(total)+"```" - - logThis("Returning final result of dirsize") - await message.edit(content=returnText)