-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathsize_csv.py
More file actions
38 lines (29 loc) · 904 Bytes
/
size_csv.py
File metadata and controls
38 lines (29 loc) · 904 Bytes
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
# Usage:
#
# python3 size_csv.py api_level/31/*.(otf|ttf|ttc)
#
import csv
import os
import sys
def main(argv):
font_dict = {}
total_filesize = 0
total_font_count = 0
fields = ["Font", "Size (B)"]
csv_data_list = []
for fontpath in argv:
size = os.path.getsize(fontpath)
total_filesize += size
total_font_count += 1
font_dict[os.path.basename(fontpath)] = size
for key in sorted(font_dict):
print(f"{key} : {font_dict[key]}")
csv_data_list.append({fields[0]: key, fields[1]: font_dict[key]})
print(f"\nTotal size: {total_filesize}")
print(f"Total fonts: {total_font_count}")
with open("fontsize.csv", "w") as csvfile:
csvwriter = csv.DictWriter(csvfile, fieldnames=fields)
csvwriter.writeheader()
csvwriter.writerows(csv_data_list)
if __name__ == "__main__":
main(sys.argv[1:])