summaryrefslogtreecommitdiff
path: root/check/commands/imagehash/query.py
diff options
context:
space:
mode:
authorJules Laplace <julescarbon@gmail.com>2019-04-15 13:35:21 +0200
committerJules Laplace <julescarbon@gmail.com>2019-04-15 13:35:21 +0200
commit229ddbb5cbf228b13b44ecaa10ef931c68b97e5c (patch)
treebd3f095d57b8b8252551b6bc61ec3f3e9d53f146 /check/commands/imagehash/query.py
parent7a1f5eb87d71acd5466b08a23ee0f98ea7edf28c (diff)
query api
Diffstat (limited to 'check/commands/imagehash/query.py')
-rw-r--r--check/commands/imagehash/query.py18
1 files changed, 17 insertions, 1 deletions
diff --git a/check/commands/imagehash/query.py b/check/commands/imagehash/query.py
index 4c51324..f5d3a54 100644
--- a/check/commands/imagehash/query.py
+++ b/check/commands/imagehash/query.py
@@ -3,8 +3,11 @@ Search the database for an image
"""
import click
+import os
-from app.models.sql_factory import search_by_phash, add_phash
+from app.models.sql_factory import search_by_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',
@@ -16,3 +19,16 @@ def cli(ctx, opt_fn):
Search the database for an image
"""
print('Searching for 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)
+
+ res = search_by_hash(hash)
+ print("search by hash:", res)
+
+ res =search_by_phash(phash)
+ print("search by phash:", res)