Skip to content

Instantly share code, notes, and snippets.

@Kadrian
Last active August 29, 2015 14:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Kadrian/f12c5d65ab4911fc5ead to your computer and use it in GitHub Desktop.
Save Kadrian/f12c5d65ab4911fc5ead to your computer and use it in GitHub Desktop.
SCSS Statistics Analysis
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
print
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