Skip to content

Instantly share code, notes, and snippets.

@igorzakhar
Last active February 1, 2018 12:09
Show Gist options
  • Save igorzakhar/32357176972f8aa6a54515ef28a538b2 to your computer and use it in GitHub Desktop.
Save igorzakhar/32357176972f8aa6a54515ef28a538b2 to your computer and use it in GitHub Desktop.
import os
import requests
def open_file(file):
with open(file, 'rb') as file:
return file.read()
def save_file(file, response):
with open(file, 'w') as file:
file.write(response)
def minify(url, file):
# path = '{}{}'.format(dir, file)
fp = open_file(file)
data = {'input': fp}
response = requests.post(url, data=data)
save_file(file, response.text)
if __name__ == '__main__':
dir_js = 'js/'
dir_css = 'css/'
api_js = 'https://javascript-minifier.com/raw'
api_css = 'https://cssminifier.com/raw'
list_js_files = list(map(lambda f: dir_js + f, os.listdir(dir_js)))
list_css_files = list(map(lambda f: dir_css + f, os.listdir(dir_css)))
list_all_files = [*list_js_files, *list_css_files]
for file in list_all_files:
if file.endswith('.css'):
minify(api_css, file)
else:
minify(api_js, file)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment