def get_all_data_types(): db = get_database() req_data_type = request.args.get('datatype') req_date = request.args.get('date') limit = request.args.get('limit') or 10 offset = request.args.get('offset') or 0 if not req_data_type: log.info('Fetching all data types') fields = {} script = get_script_path(SELECT_ALL_DATA_TYPES) elif req_data_type and req_date: log.info('Fetching by type ({}), limited by date ({})'.format( req_data_type, req_date)) fields = { 'datatype': req_data_type, 'anydate': req_date, 'limit': limit, 'offset': offset } script = get_script_path(SELECT_BY_DATA_TYPES_ON_DATE) else: log.info('Fetching by data type: {}'.format(req_data_type)) fields = {'datatype': req_data_type, 'limit': limit, 'offset': offset} script = get_script_path(SELECT_BY_DATA_TYPES) entities = db.execute_script(script, **fields) if not entities: log.info('No entities found for data type: {}'.format(req_data_type)) return responding.no_content(entities) log.debug('Entities found: {}'.format(entities)) return responding.ok(entities)
def get_database_entries(query, script_path): log.info('Fetching all entries with value: {}'.format(query)) db = get_database() script = get_script_path(script_path) results = db.execute_script(script, **query) if not results: log.info('No entries found with value: {}'.format(query)) return responding.no_content(results) log.debug('Entries with {}: {}'.format(query, results)) return responding.ok(results)
def get_sha_for_uuid(uuid): db = get_database() uuid_dict = {'uuid': uuid} log.info('Fetching entry with uuid: {}'.format(uuid)) script = get_script_path(SELECT_DUP_BY_UUID) entities = db.execute_script(script, **uuid_dict) if not entities: log.info('No entries found with uuid: {}'.format(uuid)) return responding.no_content(entities) log.debug('Entity found: {}'.format(entities)) return responding.ok(entities)
def get_duplicates_by_sha(sha_256): db = get_database() sha_dict = {'sha_256': sha_256} log.info('Fetching all entries with sha-256: {}'.format(sha_256)) script = get_script_path(SELECT_DUP_BY_SHA) duplicates = db.execute_script(script, **sha_dict) if not duplicates: log.info('No entries found with sha-256: {}'.format(sha_256)) return responding.no_content(duplicates) log.debug('Entries with sha-256: {}, {}'.format(sha_256, duplicates)) return responding.ok(duplicates)
def get_data_type_of_uuid(uuid): db = get_database() query_dict = {'uuid': uuid} log.info('Fetching entry with uuid: {}'.format(uuid)) script = get_script_path(SELECT_BY_UUID) items = db.execute_script(script, **query_dict) if not items: log.info('No entry found with uuid: {}'.format(uuid)) return responding.no_content(items) log.debug('Entry with uuid: {}, {}'.format(uuid, items)) return responding.ok(items)
def get_docs_by_lang(lang): db = get_database() lang_dict = {'lang': lang} log.info('Fetching all entries with lang: {}'.format(lang)) script = get_script_path(SELECT_DOC_BY_LANG) docs = db.execute_script(script, **lang_dict) if not docs: log.info('No entries found with lang: {}'.format(lang)) return responding.no_content(docs) log.debug('Entries with lang: {}, {}'.format(lang, docs)) return responding.ok(docs)
def get_faces_with_img_sha256(hash_digest): db = get_database() uuid_dict = {'hash_digest': hash_digest} log.info(f'Fetching entry with sha256: {hash_digest}') script = get_script_path(SELECT_FACES_BY_IMG_UUID) entities = db.execute_script(script, **uuid_dict) if not entities: log.info('No entries found with uuid: {}'.format(hash_digest)) return responding.no_content(entities) log.debug('Entity found: {}'.format(entities)) return responding.ok(entities)
def get_items_greater_than_size(size): db = get_database() size_dict = {'data_size': size} log.info('Fetching all entries with size greater than: {}'.format(size_dict)) script = get_script_path(SELECT_ITEMS_GT_SIZE) items = db.execute_script(script, **size_dict) if not items: log.info('No entries found with size greater than: {}'.format(size)) return responding.no_content(items) log.debug('Entries with size greater than: {}, {}'.format(size, items)) return responding.ok(items)
def get_gpsinfo_by_geohash(geohash): db = get_database() query_dict = {'geohash': geohash + '%'} log.info('Fetching GPS data by geohash: {}'.format(query_dict)) script = get_script_path(SELECT_BY_GEOHASH) items = db.execute_script(script, **query_dict) if not items: log.info('No entry found with geohash: {}'.format(geohash)) return responding.no_content(items) log.debug('Entries found with geohash={}: {}'.format(geohash, items)) return responding.ok(items)
def get_exif_by_uuid(uuid): db = get_database() limit = request.args.get('limit') or 10 offset = request.args.get('offset') or 0 query_dict = {'limit': limit, 'offset': offset, 'uuid': uuid} log.info('Fetching entry with uuid: {}'.format(uuid)) script = get_script_path(SELECT_BY_UUID) items = db.execute_script(script, **query_dict) if not items: log.info('No entry found with uuid: {}'.format(uuid)) return responding.no_content(items) log.debug('Entry with uuid: {}, {}'.format(uuid, items)) return responding.ok(items)
def get_all_exif(): db = get_database() limit = request.args.get('limit') or 10 offset = request.args.get('offset') or 0 query_dict = {'limit': limit, 'offset': offset} log.info('Fetching all entries'.format()) script = get_script_path(SELECT_ALL) items = db.execute_script(script, **query_dict) if not items: log.info('No entries found') return responding.no_content(items) log.debug('Entries found: {}'.format(items)) return responding.ok(items)
def get_sequences_by_video_reference(vid_ref): db = get_database() limit = request.args.get('limit') or 10 offset = request.args.get('offset') or 0 query = {'video_reference': vid_ref, 'limit': limit, 'offset': offset} log.info('Fetching all entries by query args: {}'.format(query)) script = get_script_path(SELECT_BY_VID_REF) results = db.execute_script(script, **query) if not results: log.info('No entries found with value: {}'.format(query)) return responding.no_content(results) log.debug('Entries with {}: {}'.format(query, results)) return responding.ok(results)
def find_users_with_samples(): db = get_database() limit = request.args.get('limit') or 10 offset = request.args.get('offset') or 0 query_dict = {'limit': limit, 'offset': offset} log.info('Finding users with sample image. {}'.format(query_dict)) script = get_script_path(SELECT_USERS_WITH_SAMPLE) faces = db.execute_script(script, **query_dict) if not faces: err = 'Could not find any users with sample image' log.info(err) return responding.no_content(faces) return responding.ok(faces)
def thumbnail_by_uuid(uuid): db = get_database() uuid_dict = {'uuid': uuid} log.info('Fetching thumbnail for uuid: {}'.format(uuid)) script = get_script_path(SELECT_THUMB_BY_UUID) thumbnails = db.execute_script(script, **uuid_dict) log.debug('Thumbnails found: {}'.format(thumbnails)) if not thumbnails: err = 'No thumbnail found with UUID: {}'.format(uuid) log.warning(err) return responding.no_content(err) log.debug('Thumbnail uuid: {}'.format(uuid)) return send_file(io.BytesIO(thumbnails[0].get('thumbnail', b'')), attachment_filename=uuid)
def get_sequence_by_id(seq_id): db = get_database() limit = request.args.get('limit') or 10 offset = request.args.get('offset') or 0 query = {'id': seq_id, 'limit': limit, 'offset': offset} log.info('Fetching binary data by query args: {}'.format(query)) script = get_script_path(SELECT_BY_ID) results = db.execute_script(script, **query) if not results: log.info('No entries found with value: {}'.format(query)) return responding.no_content(results) log.debug('Sequence id={}'.format(seq_id)) return send_file( io.BytesIO(results[0].get('gif', b'')), attachment_filename=seq_id )
def find_similar_images(uuid): db = get_database() log.info('Started looking for similar encodings') uuid_dict = {'uuid': uuid} script = get_script_path(SELECT_FACES_BY_IMG_UUID) faces = db.execute_script(script, **uuid_dict) if not faces: err = 'Could not find any face encodings related to UUID: {}'.format(uuid) log.info(err) return responding.no_content(faces) script = get_script_path(SELECT_FACES_BY_USER_ID) res = [ { **face, 'similar': db.execute_script( script, **{'user_id': face.get('user_id')} ) } for face in faces ] return responding.ok(res)