示例#1
0
def hello_world():
    """
    Heartbeat
    :return:
    """
    msg = {'message': "Hello Copernicus."}
    schema = MessageSchema()
    return misc.create_response(jsonify(schema.dump(msg).data))
示例#2
0
def list():
    # return misc.create_response(jsonify({'files':list_files()}))
    result = list_files()
    #transform
    msg = {'message': "All currently available files.", 'data': result}
    schema = MessageSchema()
    result = schema.dump(msg)

    return misc.create_response(jsonify(result.data))
示例#3
0
def retrieve_copernicus_file():
    """
    Retrieve the grib file for a given date.
    Example query: /retrieve?timestamp=2017-09-13T15:21:20%2B00:00
    # :return: filename    """
    try:
        date_arg = validate_request_parameters()

    except ValueError, e:
        return misc.create_response(jsonify(message=e.message), 400)
示例#4
0
def parse_file_():
    """
    Retrieves the parsed information  by specifying the file, the timestamp and latitude + longitude. Don't forget
    to encode the plus sign '+' = %2B!
    Example: GET /parse/data/ecmwf/an-2017-09-14.grib?timestamp=2017-09-16T15:21:20%2B00:00&lat=48.398400&lon=9.591550
    :param fileName: path to a retrieved ecmwf grib file.
    :return: OK including json content or empty not found
    """
    try:
        [point, date] = validate_request_parameters()
    except ValueError, e:
        return misc.create_response(jsonify(message=e.message), 400)
示例#5
0
        return misc.create_response(jsonify(message=e.message), 400)

    file_name = misc.build_file_name(date)
    path_to_file = file_directory + os.sep + file_name
    files = file_status.get_available_files()

    if file_name not in files or not os.path.isfile(path_to_file):
        msg = {
            'message':
            'Given filename={} could not be found in the available files are attached.'
            .format(file_name, files),
            'data': {
                'files': files
            }
        }
        return misc.create_response(jsonify(transform_message(msg).data), 404)

    result = cache.cache.get(request.url)
    # check cache
    if not result:
        result = parse_action.parse(path_to_file, point, date)
    return Response(json.dumps(transform(result),
                               default=CopernicusData.json_serial,
                               indent=2),
                    mimetype="text/json",
                    status=200)


def transform(result):
    # refer to: http://marshmallow.readthedocs.io/en/latest/quickstart.html#filtering-output to filter the output
    # Only output the type and value!
示例#6
0
        date_arg = validate_request_parameters()

    except ValueError, e:
        return misc.create_response(jsonify(message=e.message), 400)

    response = cache.cache.get(request.url.split("T")[0])
    # check cache hit
    if response:
        # transform
        msg = {
            'message': "Cache hit.",
            'data': {
                'fileName': response.split("/")[-1]
            }
        }
        return misc.create_response(jsonify(transform(msg).data))

    # no cache hit
    latestRetrievalDate = datetime.utcnow() - timedelta(
        days=copernicus_enums.DataSets.CAMS.value['delayDays'])
    if ((date_arg - latestRetrievalDate).days <= 0):
        result = retrieve_action.retrieve_file(date_arg)
        return misc.create_response(jsonify(transform(result).data))
    else:
        msg = {
            'message': "Cannot retrieve files for this date.",
            'data': {
                'latest_retrieval_date':
                latestRetrievalDate.date().isoformat()
            }
        }