Created
August 23, 2019 20:03
-
-
Save 0x9900/d07f38123e1551481a593300b04887f7 to your computer and use it in GitHub Desktop.
Compress CSS files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# | |
# (c) W6BSD Fred Cirera | |
# https://github.com/0x9900/ | |
# | |
import argparse | |
import logging | |
import os.path | |
import sys | |
import requests | |
CSSMINI_URL = 'https://cssminifier.com/raw' | |
logging.basicConfig(format='%(asctime)s %(levelname)s: %(message)s', | |
datefmt='%H:%M:%S', level=logging.INFO) | |
def minify(filename): | |
with open(filename, 'rb') as fdin: | |
data = {'input': fdin.read()} | |
response = requests.post(CSSMINI_URL, data=data) | |
return response.text | |
def main(argv=sys.argv[1:]): | |
parser = argparse.ArgumentParser(description='css minifier') | |
parser.add_argument('-f', '--files', nargs="+", help='List all the css files') | |
opts = parser.parse_args(argv) | |
for filename in opts.files: | |
if not os.path.exists(filename): | |
logging.error('%s not found') | |
continue | |
css_minified = minify(filename) | |
name, ext = os.path.splitext(filename) | |
minifile = '.'.join([name, 'min']) + ext | |
with open(minifile, 'wb') as fdout: | |
fdout.write(css_minified) | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment