Validate CSV output schemas
Also moved code dir to src. There are reasons to do standard things in standard ways. While it is possible to get the `code/` directory to work, and recognize it as a package path, this requires wrangling the pyproject.toml file. Additionally, any import from the `code.something` path automatically shadows the python stdlib `code` module. While it may not be necessary, it still is good to not shadow standard library modules.
This commit is contained in:
parent
de96b67fac
commit
2faeda87c3
14 changed files with 111 additions and 7 deletions
|
|
@ -1,41 +0,0 @@
|
|||
import csv
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
def filesize_csv(input_dir: Path, output_dir: Path) -> None:
|
||||
output_file = output_dir / "files.csv"
|
||||
with output_file.open("w") as fw:
|
||||
writer = csv.writer(fw)
|
||||
writer.writerow(["date", "filename", "mtime", "filesize"])
|
||||
|
||||
for j in input_dir.glob("*.json"):
|
||||
p_date = j.stem
|
||||
p_fname = j.name
|
||||
stat = j.stat()
|
||||
p_mtime = stat.st_mtime
|
||||
p_size = stat.st_size
|
||||
writer.writerow([p_date, p_fname, p_mtime, p_size])
|
||||
|
||||
|
||||
def ensure_dirs(input_dir: Path, output_dir: Path):
|
||||
if not input_dir.is_dir():
|
||||
raise ValueError
|
||||
output_dir.mkdir(exist_ok=True, parents=True)
|
||||
|
||||
|
||||
def main(input: str, output: str) -> None:
|
||||
input_dir = Path(input)
|
||||
output_dir = Path(output)
|
||||
ensure_dirs(input_dir, output_dir)
|
||||
filesize_csv(input_dir, output_dir)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
import sys
|
||||
|
||||
if not len(sys.argv) == 3:
|
||||
print("Please provide exactly one input directory and one output directory.")
|
||||
sys.exit(1)
|
||||
inp = sys.argv[1]
|
||||
out = sys.argv[2]
|
||||
main(inp, out)
|
||||
Loading…
Add table
Add a link
Reference in a new issue