diff options
Diffstat (limited to 'check/commands/imagehash/add.py')
| -rw-r--r-- | check/commands/imagehash/add.py | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/check/commands/imagehash/add.py b/check/commands/imagehash/add.py index 37aad0d..73f8b69 100644 --- a/check/commands/imagehash/add.py +++ b/check/commands/imagehash/add.py @@ -3,8 +3,11 @@ Add a file to the database """ import click +import os -# from app.models.sql_factory import load_sql_datasets +from app.models.sql_factory import search_by_phash, add_phash +from app.utils.im_utils import compute_phash_int +from app.utils.file_utils import sha256 @click.command() @click.option('-i', '--input', 'opt_fn', @@ -18,3 +21,14 @@ def cli(ctx, opt_fn, opt_upload): Add a single file """ print('Adding a file...') + if not os.path.exists(opt_fn): + print("File does not exist") + return + + hash = sha256(opt_fn) + phash = compute_phash_int(opt_fn) + + dir, fn = os.path.split(opt_fn) + root, ext = os.path.splitext(fn) + + add_phash(sha256=hash, phash=phash, ext=ext) |
