Created
July 27, 2016 20:19
-
-
Save yawa2/f9722128b1b31497bb1e8d268d60d4c8 to your computer and use it in GitHub Desktop.
This file contains 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
# http://wykop.pl/wpis/18764611 | |
# http://wykop.pl/ludzie/yawa2 | |
# Python 3 | |
from collections import defaultdict | |
from os import path, stat, walk | |
from sys import argv | |
def collect_data(directory_name): | |
data = defaultdict(lambda: [0, 0]) | |
total_qty = 0 | |
for directory_path, _, file_names in walk(directory_name): | |
for file_name in file_names: | |
ext = path.splitext(file_name)[1].split('.')[-1] | |
file_path = path.join(directory_path, file_name) | |
data[ext][0] += stat(file_path).st_size | |
data[ext][1] += 1 | |
total_qty += 1 | |
return total_qty, data | |
def main(directory_name, output_file_name): | |
(total_qty, data) = collect_data(directory_name) | |
with open(output_file_name, 'w') as out_file: | |
for ext, (size, qty) in sorted(data.items(), key=lambda x: x[1][1], reverse=True): | |
out_file.write('%5s%14dB%60s\n' % (ext, size, round(50 * qty/total_qty) * '#')) | |
if __name__ == '__main__': | |
main(argv[1], argv[2]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment