/
run_mincss.py
executable file
·75 lines (69 loc) · 1.86 KB
/
run_mincss.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/usr/bin/env python
from __future__ import print_function
import sys, os
import time
sys.path.insert(0, os.path.abspath('.'))
from mincss.processor import Processor
DEFAULT_URL = 'http://localhost:9000/page.html'
def run(url):
p = Processor()
t0 = time.time()
p.process(url)
t1 = time.time()
print("INLINES ".ljust(79, '-'))
total_size_before = 0
total_size_after = 0
# for each in p.inlines:
# print("On line %s" % each.line)
# print('- ' * 40)
# print("BEFORE")
# print(each.before)
# total_size_before += len(each.before)
# print('- ' * 40)
# print("AFTER:")
# print(each.after)
# total_size_after += len(each.after)
# print("\n")
#
# print("LINKS ".ljust(79, '-'))
# for each in p.links:
# print("On href %s" % each.href)
# print('- ' * 40)
# print("BEFORE")
# print(each.before)
# total_size_before += len(each.before)
# print('- ' * 40)
# print("AFTER:")
# print(each.after)
# print("\n")
#
# print("LINKS ".ljust(79, '-'))
# for each in p.links:
# print("On href %s" % each.href)
# print('- ' * 40)
# print("BEFORE")
# print(each.before)
# total_size_before += len(each.before)
# print('- ' * 40)
# print("AFTER:")
# print(each.after)
# total_size_after += len(each.after)
# print("\n")
print(
"TOOK:".ljust(20),
"%.5fs" % (t1 - t0)
)
print(
"TOTAL SIZE BEFORE:".ljust(20),
"%.1fKb" % (total_size_before / 1024.0)
)
print(
"TOTAL SIZE AFTER:".ljust(20),
"%.1fKb" % (total_size_after / 1024.0)
)
if __name__ == '__main__':
urls = sys.argv[1:]
if not urls:
urls = [DEFAULT_URL]
for url in urls:
run(url)