diff --git a/main.py b/main.py new file mode 100644 index 0000000..c0274f7 --- /dev/null +++ b/main.py @@ -0,0 +1,57 @@ +import requests +import tqdm +import tarfile +import os +import shutil + +discordUrl = "https://discord.com/api/download?platform=linux&format=tar.gz" +tmpDir = "/tmp/dup/" +confDir = "~/.config/" +installDir = os.path.expanduser("~") + "/.local/lib/Discord" + +def download(url: str, dest: str): + with open(tmpDir + dest, 'wb') as f: + with requests.get(url, stream=True) as r: + r.raise_for_status() + totalLength = int(r.headers.get('content-length', 0)) + + tqdm_params = { + 'desc': dest, + 'total': totalLength, + 'miniters': 1, + 'bar_format' : "{desc}: |{bar:40}| {percentage:3.1f}% ", + } + with tqdm.tqdm(**tqdm_params) as pb: + for chunk in r.iter_content(chunk_size=8192): + pb.update(len(chunk)) + f.write(chunk) + + def rm(file): + print("TBA") + def rmdir(): + print("TBA") + def mkdir(): + print("TBA") + +def installDiscord(): + #os.mkdir(tmpDir) + + print("Downloading Discord...") + download(discordUrl, "discord.tar.gz") + + print("Extracting..." ) + file = tarfile.open(tmpDir+"/discord.tar.gz") + os.mkdir("/tmp/dup/discord") + file.extractall(tmpDir+"/discord") + file.close() + + print("Installing...") + shutil.rmtree(installDir) + shutil.move(tmpDir+"/discord/Discord", installDir) + + print("Cleaning up...") + # os.remove(tmpDir+"discord.tar.gz") + shutil.rmtree(tmpDir) + + +installDiscord()