-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdownloader.py
31 lines (29 loc) · 1.09 KB
/
downloader.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
@bot.command(name="downloader", usage='<url> <script or theme>', description="Download a theme or script file")
async def download(ctx, url: str, loc: str = 'scripts'):
await ctx.message.delete()
filename = url.split('/')[-1].replace(" ", "_")
if loc == 'script':
fileloc = 'scripts'
elif loc == 'theme':
fileloc = 'themes'
else:
await ctx.nighty_send("Invalid folder")
data_path = getDataPath()
file_path = os.path.join(data_path, fileloc , filename)
r = requests.get(url, stream=True)
if r.ok:
with open(file_path, 'wb') as f:
for chunk in r.iter_content(chunk_size=1024 * 8):
if chunk:
f.write(chunk)
f.flush()
os.fsync(f.fileno())
if loc == 'theme':
zip = ZipFile(filename)
zip.extractall()
await ctx.nighty_send(f"Downloaded file {filename}")
else:
await ctx.nighty_send(f"Downloaded file {filename}")
else:
await ctx.nighty_send("Downloaded failed!")
#MYHM 398620861634183188