# -*- coding: utf-8 -*- # 通用统计:打印 style 块 hex 精确频次(只读) import re, sys, collections for path in sys.argv[1:]: with open(path, "r", encoding="utf-8") as f: src = f.read() m = re.search(r"^[ \t]*]*>[\s\S]*?", src, re.M) if not m: print(path, ": NO STYLE BLOCK") continue hexes = re.findall(r"#[0-9A-Fa-f]{3,6}\b", m.group(0)) print("=== %s : total %d unique %d ===" % (path, len(hexes), len(set(hexes)))) for h, c in sorted(collections.Counter(hexes).items(), key=lambda kv: (-kv[1], kv[0])): print("%-9s %d" % (h, c))