-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexport_scraped_file_size.py
More file actions
43 lines (32 loc) · 983 Bytes
/
export_scraped_file_size.py
File metadata and controls
43 lines (32 loc) · 983 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
39
40
41
42
43
#!/usr/bin/env python3
import plac
from pathlib import Path
mib = 1024 ** 2
def main(
file_ext: ("The file extension to process.", "option", "e"),
inp: ("The directory to search.", "option", "d"),
output: ("The file to write metrics.", "option", "o"),
):
ext = "." + file_ext
p = Path(inp)
files = [
content
for content in p.iterdir()
if content.suffix == ext and content.is_file()
]
file_size_dict = {file.name: file.stat().st_size / mib for file in files}
out = Path(output)
if not out.exists():
out.parent.mkdir(parents=True, exist_ok=True)
out.touch()
with out.open(mode="w") as writer:
for fname, size in file_size_dict.items():
writer.write(
'scraped_file_size{directory="'
+ fname
+ '"} '
+ "{:.1f}".format(size)
+ "\n"
)
if __name__ == "__main__":
plac.call(main)