-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcollect.py
More file actions
executable file
·49 lines (40 loc) · 1.16 KB
/
collect.py
File metadata and controls
executable file
·49 lines (40 loc) · 1.16 KB
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
44
45
46
47
48
49
#!/usr/bin/env python3
import argparse
import pathlib
from dotenv import load_dotenv
from repositories.image.files import ImageFilesRepository
from repositories.image.sqllite_db import Sqllite3ImageRepository
from repositories.image.sqllite_db import Sqllite3ImageRepositoryExistsException
load_dotenv()
def main():
parser = argparse.ArgumentParser(
prog="collect.py",
description='Create database of image files',
epilog="may The Force be with you!",
)
parser.add_argument(
"--db",
nargs=1,
type=str,
required=True,
help="path to db",
)
parser.add_argument(
"--path",
nargs=1,
type=str,
required=True,
help="path to get list image",
)
args = parser.parse_args()
db_file: str = args.db[0]
image_db = Sqllite3ImageRepository(db_file)
path = pathlib.Path(args.path[0])
images = ImageFilesRepository(path)
for file in images.get_list():
try:
image_db.add(file)
except Sqllite3ImageRepositoryExistsException:
print(f"{file} is exists in database")
if __name__ == "__main__":
main()