Skip to content

Instantly share code, notes, and snippets.

@jiverson
Forked from ralsina/apply_mincss.py
Created February 28, 2014 06:20
Show Gist options
  • Save jiverson/9266252 to your computer and use it in GitHub Desktop.
Save jiverson/9266252 to your computer and use it in GitHub Desktop.
import os
import sys
output_folder = os.path.abspath(sys.argv[1])
from mincss.processor import Processor
p = Processor()
urls = []
css_files = {}
for root, dirs, files in os.walk(output_folder):
for f in files:
url = os.path.join(output_folder, root, f)
if url.endswith('.css'):
fname = os.path.basename(url)
if fname in css_files:
print "You have two CSS files with the same name and that confuses me."
sys.exit(1)
css_files[fname] = url
if not f.endswith('.html'):
continue
urls.append(url)
p.process(*urls)
for inline in p.links:
fname = os.path.basename(inline.href)
print css_files[fname]
print "===>", inline.href, len(inline.before), len(inline.after)
with open(css_files[fname], 'wb+') as outf:
outf.write(inline.after)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment