add: copy tools
This commit is contained in:
parent
3831d57fe6
commit
0b1e2479c1
3
.gitignore
vendored
3
.gitignore
vendored
@ -1,3 +1,4 @@
|
||||
venv
|
||||
*.pyc
|
||||
output
|
||||
test_out
|
||||
test_in
|
34
tools/copy.py
Normal file
34
tools/copy.py
Normal file
@ -0,0 +1,34 @@
|
||||
import uuid
|
||||
import sys
|
||||
import os
|
||||
import argparse
|
||||
import hashlib
|
||||
import shutil
|
||||
from progress.bar import Bar
|
||||
|
||||
def argument_parsing():
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument("input_folder", help="the folder of your raws", type=str)
|
||||
parser.add_argument("output_folder", help="the location of your website", type=str)
|
||||
args = parser.parse_args()
|
||||
|
||||
return args.input_folder, args.output_folder
|
||||
|
||||
def main():
|
||||
input_folder, output_folder = argument_parsing()
|
||||
files: list[str] = [os.path.join(input_folder, f) for f in os.listdir(input_folder)]
|
||||
files = [f for f in files if os.path.isfile(f)]
|
||||
with Bar("generating...", max=len(files)) as bar:
|
||||
for file in files:
|
||||
with open(file, 'rb') as f:
|
||||
image_data = f.read()
|
||||
file_extention: str = file.split(".")[-1]
|
||||
file_name: str = hashlib.sha256(image_data).hexdigest()
|
||||
path: str = os.path.join(output_folder, file_name)
|
||||
if not os.path.exists(path):
|
||||
os.makedirs(path)
|
||||
shutil.copy2(file, os.path.join(path, file_name + "." + file_extention))
|
||||
bar.next()
|
||||
|
||||
if __name__ == "__main__":
|
||||
exit(main())
|
Loading…
Reference in New Issue
Block a user