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
|
"""
Test the API
"""
import click
import os
import glob
import requests
mime_types = {
'.png': 'image/png',
'.gif': 'image/gif',
'.jpg': 'image/jpeg',
'.jpeg': 'image/jpeg',
}
@click.command()
@click.option('-i', '--input', 'opt_input_fn',
required=True,
help="Image to test the API with")
@click.pass_context
def cli(ctx, opt_input_fn):
"""
Query the API with a test image
"""
with open(opt_input_fn, 'rb') as f:
fn = os.path.basename(opt_input_fn)
fpart, ext = os.path.splitext(fn)
if ext not in mime_types:
print("Invalid filetype: {}".format(ext))
query = [
('q', (fn, f, mime_types[ext]))
]
print("Testing match API")
r = requests.post('http://0.0.0.0:5000/api/v1/match', files=query)
print(r.json())
|