blob: f5d3a54e3941232bf40323464d32453844f0fdd1 (
plain)
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
|
"""
Search the database for an image
"""
import click
import os
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',
required=True,
help="File to search")
@click.pass_context
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)
|