Last active
August 29, 2015 14:11
-
-
Save Kadrian/f12c5d65ab4911fc5ead to your computer and use it in GitHub Desktop.
SCSS Statistics Analysis
This file contains hidden or 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
import sys | |
def analyzeFile(filename): | |
f = open(filename) | |
selectors, rules = [], [] | |
for w in f.readlines(): | |
w = w.strip() | |
if len(w) > 2: | |
if (w.startswith('.') or | |
w.startswith('/') or | |
w.startswith('#') or | |
w.startswith('$') or | |
w.startswith('&') or | |
w.startswith('*') or | |
w.startswith('@') or | |
w.startswith('-') or | |
'}' in w or | |
'{' in w or | |
':' not in w | |
): | |
selectors.append(w) | |
else: | |
rules.append(w) | |
rulesDic = {} | |
for line in sorted(rules): | |
rule = line.split(':') | |
if rule[0] not in rulesDic: | |
rulesDic[rule[0]] = [] | |
rulesDic[rule[0]].append(rule[1].strip().replace(';', '')) | |
for k, v in sorted(rulesDic.items(), key=lambda x: len(x[1])): | |
print str(len(v)) + " times: " + k | |
for val in sorted(v): | |
print "\t" + val | |
if len(sys.argv) != 2: | |
print "Please give me a scss file" | |
else: | |
analyzeFile(sys.argv[1]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment