Ejemplo n.º 1
0
def exec_pipeline():
    # parse POST form args
    query = request.form['q']
    engine = request.form.get('engine', 'google_web')
    postproc_module = request.form.get('postproc_module',
                                       None)  # default to no postproc module
    postproc_extra_prms = request.form.get('postproc_extra_prms', None)
    if postproc_extra_prms:
        postproc_extra_prms = json.loads(postproc_extra_prms)
    custom_local_path = request.form.get('custom_local_path', None)
    # < default to returning list only if not using postproc module >
    return_dfiles_list = request.form.get('return_dfiles_list',
                                          (postproc_module == None))
    return_dfiles_list = (int(return_dfiles_list) == 1)

    # prepare query params
    query_timeout = request.form.get('query_timeout', -1.0)
    query_timeout = float(query_timeout)
    query_params = dict()
    for param_nm in ['size', 'style']:
        if param_nm in request.form:
            query_params[param_nm] = request.form[param_nm]
    if 'num_results' in request.form:
        query_params['num_results'] = int(request.form['num_results'])
    # execute query
    query_res_list = http_service_helper.imsearch_query(
        query, engine, query_params, query_timeout)
    print 'Query for %s completed: %d results retrieved' % (
        query, len(query_res_list))
    #query_res_list = query_res_list[:5] # DEBUG CODE
    # prepare download params
    imgetter_params = dict()
    for param_nm in ['improc_timeout', 'per_image_timeout']:
        if param_nm in request.form:
            imgetter_params[param_nm] = float(request.form[param_nm])
    for param_nm in ['resize_width', 'resize_height']:
        if param_nm in request.form:
            imgetter_params[param_nm] = int(request.form[param_nm])
    # download images
    print 'Downloading for %s started: %d sec improc_timeout, %d sec per_image_timeout' % (
        query, imgetter_params['improc_timeout']
        if imgetter_params['improc_timeout'] else -1,
        imgetter_params['per_image_timeout']
        if imgetter_params['per_image_timeout'] else -1)
    dfiles_list = http_service_helper.imsearch_download_to_static(
        query_res_list, postproc_module, postproc_extra_prms,
        custom_local_path, imgetter_params, zmq_context)
    print 'Downloading for %s completed: %d images retrieved' % (
        query, len(dfiles_list))
    # convert pathnames to URL paths (if not running locally and specifying
    # a custom path)
    if not custom_local_path:
        dfiles_list = http_service_helper.make_url_dfiles_list(dfiles_list)

    if return_dfiles_list:
        return Response(json.dumps(dfiles_list), mimetype='application/json')
    else:
        return 'DONE'
def exec_pipeline():
    # parse POST form args
    query = request.form['q']
    engine = request.form.get('engine', 'google_web')
    postproc_module = request.form.get('postproc_module', None) # default to no postproc module
    postproc_extra_prms = request.form.get('postproc_extra_prms', None)
    if postproc_extra_prms:
        postproc_extra_prms = json.loads(postproc_extra_prms)
    custom_local_path = request.form.get('custom_local_path', None)
    # < default to returning list only if not using postproc module >
    return_dfiles_list = request.form.get('return_dfiles_list', (postproc_module == None))
    return_dfiles_list = (int(return_dfiles_list) == 1)

    # prepare query params
    query_timeout = request.form.get('query_timeout', -1.0)
    query_timeout = float(query_timeout)
    query_params = dict()
    for param_nm in ['size', 'style']:
        if param_nm in request.form:
            query_params[param_nm] = request.form[param_nm]
    if 'num_results' in request.form:
        query_params['num_results'] = int(request.form['num_results'])
    # execute query
    query_res_list = http_service_helper.imsearch_query(query, engine,
                                                        query_params, query_timeout)
    print 'Query for %s completed: %d results retrieved' % (query, len(query_res_list))
    #query_res_list = query_res_list[:5] # DEBUG CODE
    # prepare download params
    imgetter_params = dict()
    for param_nm in ['improc_timeout', 'per_image_timeout']:
        if param_nm in request.form:
            imgetter_params[param_nm] = float(request.form[param_nm])
    for param_nm in ['resize_width', 'resize_height']:
        if param_nm in request.form:
            imgetter_params[param_nm] = int(request.form[param_nm])
    # download images
    print 'Downloading for %s started: %d sec improc_timeout, %d sec per_image_timeout' % (query,
                                                                                           imgetter_params['improc_timeout'] if imgetter_params['improc_timeout'] else -1,
                                                                                           imgetter_params['per_image_timeout'] if imgetter_params['per_image_timeout'] else -1)
    dfiles_list = http_service_helper.imsearch_download_to_static(query_res_list,
                                                                  postproc_module,
                                                                  postproc_extra_prms,
                                                                  custom_local_path,
                                                                  imgetter_params,
                                                                  zmq_context)
    print 'Downloading for %s completed: %d images retrieved' % (query, len(dfiles_list))
    # convert pathnames to URL paths (if not running locally and specifying
    # a custom path)
    if not custom_local_path:
        dfiles_list = http_service_helper.make_url_dfiles_list(dfiles_list)

    if return_dfiles_list:
        return Response(json.dumps(dfiles_list), mimetype='application/json')
    else:
        return 'DONE'
def download():
    # parse POST data
    query_res_list = request.json
    if not query_res_list:
        raise ValueError("Input must be 'application/json' encoded list of urls")
    # download images
    dfiles_list = http_service_helper.imsearch_download_to_static(query_res_list)
    # convert pathnames to URL paths
    url_dfiles_list = http_service_helper.make_url_dfiles_list(dfiles_list)

    return Response(json.dumps(url_dfiles_list), mimetype='application/json')
Ejemplo n.º 4
0
def download():
    # parse POST data
    query_res_list = request.json
    if not query_res_list:
        raise ValueError("Input must be 'application/json' encoded list of urls")
    # download images
    dfiles_list = http_service_helper.imsearch_download_to_static(query_res_list)
    # convert pathnames to URL paths
    url_dfiles_list = http_service_helper.make_url_dfiles_list(dfiles_list)
    
    return Response(json.dumps(url_dfiles_list), mimetype='application/json')