summaryrefslogtreecommitdiff
path: root/check/commands/imagehash/add.py
diff options
context:
space:
mode:
authorJules Laplace <julescarbon@gmail.com>2019-04-14 20:22:19 +0200
committerJules Laplace <julescarbon@gmail.com>2019-04-14 20:22:19 +0200
commit7a1f5eb87d71acd5466b08a23ee0f98ea7edf28c (patch)
treef9bd95006105394469a67af8cfe6db115eba4b7f /check/commands/imagehash/add.py
parent890586175ff054cc01d39f9931ab2e4bae62c1e1 (diff)
add phash script
Diffstat (limited to 'check/commands/imagehash/add.py')
-rw-r--r--check/commands/imagehash/add.py16
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)