Skip to content
Snippets Groups Projects
minify.py 1.07 KiB
Newer Older
  • Learn to ignore specific revisions
  • Bye's avatar
    Bye committed
    import os, requests, tinify
    from dotenv import load_dotenv
    
    load_dotenv()
    
    tinify.key = os.environ.get("tinify_key")
    
    
    Bye's avatar
    Bye committed
    output_dir = "build"
    
    Bye's avatar
    Bye committed
    
    
    Bye's avatar
    Bye committed
    try:
        os.mkdir(output_dir)
    except FileExistsError:
        print("It's already there!!!")
    
    output_dir += "/"
    
    Bye's avatar
    Bye committed
    
    for ff in os.listdir():
    
    Bye's avatar
    Bye committed
        print(ff)
    
    Bye's avatar
    Bye committed
        if ff.endswith(".png"):
    
    Bye's avatar
    Bye committed
            if (ff == "logothing.png"):
                continue
    
    Bye's avatar
    Bye committed
    
    
    Bye's avatar
    Bye committed
            source = tinify.from_file(ff)
            source.to_file(f'{output_dir}{ff}')
    
    Bye's avatar
    Bye committed
        if ff.endswith(".mp3"):
    
    Bye's avatar
    Bye committed
            fle = open(ff, "rb")
            dst = open(f'{output_dir}{ff}', "wb+")
            dst.write(fle.read())
            fle.close()
            dst.close()
    
    Bye's avatar
    Bye committed
    
    os.system(f"terser lzs.js letters.js game.js --mangle --compress -o {output_dir}code.js")
    
    Bye's avatar
    Bye committed
    try:
        os.system(f"rm {output_dir}dbh.zip")
    except:
        print("no need to delete anything")
    
    Bye's avatar
    Bye committed
    os.system(f"advzip {output_dir}dbh.zip --add build --shrink-insane -4")
    
    Bye's avatar
    Bye committed
    
    progress = os.path.getsize(f"{output_dir}dbh.zip") / 1024
    
    # make a loading bar showing progress to 13KB
    print(f"[{'#'*(int((progress/13)*100)//10)}] {((progress/13)*100)}% ({round(progress, 3)} KB / 13 KB)")