💾 !dirsize
This commit is contained in:
@@ -136,6 +136,11 @@ class MiscCog(commands.Cog):
|
|||||||
async def downloading(self,ctx):
|
async def downloading(self,ctx):
|
||||||
await self.bedreNetflix.downloading(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
|
#Looks up on Wolfram Alpha
|
||||||
@commands.command()
|
@commands.command()
|
||||||
async def wolf(self, ctx, *, content):
|
async def wolf(self, ctx, *, content):
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import requests, imdb, discord, json, math, time, asyncio
|
import requests, imdb, discord, json, math, time, asyncio, os
|
||||||
from funcs import logThis
|
from funcs import logThis
|
||||||
|
|
||||||
radarrURL = "http://localhost:7878/api/v3/"
|
radarrURL = "http://localhost:7878/api/v3/"
|
||||||
@@ -7,6 +7,30 @@ qbittorrentURL = "http://localhost:1340/api/v2/"
|
|||||||
moviePath = "/media/plex/Server/movies/"
|
moviePath = "/media/plex/Server/movies/"
|
||||||
showPath = "/media/plex/Server/Shows/"
|
showPath = "/media/plex/Server/Shows/"
|
||||||
|
|
||||||
|
async 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):
|
||||||
|
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():
|
class BedreNetflix():
|
||||||
def __init__(self,bot):
|
def __init__(self,bot):
|
||||||
self.bot = bot
|
self.bot = bot
|
||||||
@@ -249,3 +273,28 @@ class BedreNetflix():
|
|||||||
await oldMessage.edit(content = messageText)
|
await oldMessage.edit(content = messageText)
|
||||||
else:
|
else:
|
||||||
await ctx.send(messageText)
|
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:
|
||||||
|
size = await getSize(fp,pathLength)
|
||||||
|
directories.append((str(f),size))
|
||||||
|
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)+"```"
|
||||||
|
|
||||||
|
await message.edit(content=returnText)
|
||||||
|
|||||||
Reference in New Issue
Block a user