-
Notifications
You must be signed in to change notification settings - Fork 1
/
compress.py
36 lines (30 loc) · 1.06 KB
/
compress.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import os
import requests
def getDirsList(path):
dirs = []
for subdirectories in os.walk(path):
for subdirectory in subdirectories:
if isinstance(subdirectory, str):
dirs.append(subdirectory)
return dirs
def concatFiles(dirsList, path):
os.system('del .\\' + path[1:] + '\styles.min.css')
for dir in dirsList:
localPath = dir[1:].replace('/', '\\')
os.system(f'type {os.getcwd() + localPath}\*.css >> .\\'+ path + '\styles.min.css')
os.system('cls')
def minifyCSS(path):
url = 'https://www.toptal.com/developers/cssminifier/raw'
data = {'input': open(f'.{path}/styles.min.css', 'rb').read()}
response = requests.post(url, data=data)
return response.text
def writeToFile(path, string):
text_file = open(f".{path}/styles.min.css", "w")
n = text_file.write(string)
text_file.close()
def compress(path):
dirsList = getDirsList(f'.{path}/styles')
concatFiles(dirsList, path)
minified = minifyCSS(path)
writeToFile(path, minified)
compress('/project')