def web_definition(): """ Get dataset metadata from a URL Loads the metadata for a file specified by the url and name parameters. Response is the same as for `/dataset/definition` --- parameters: - name: name in: query description: The name of the dataset file that is to be loaded required: false type: string defaultValue: "Mortality.monthly_MadrasIndia.1916_1921.tab" - name: url in: query description: The URL address of the file that is to be loaded required: false type: string defaultValue: "http://example.com/interesting/file.csv" tags: - Dataverse responses: '200': description: Dataset metadata retrieved schema: $ref: "#/definitions/DatasetSchema" default: description: Unexpected error schema: $ref: "#/definitions/Message" """ dataset_url = request.args.get('url', False) dataset_name = request.args.get('name', False) username = request.args.get('user', False) log.debug("Web dataset: {}/{}".format(dataset_url, dataset_name)) # Check whether a file has been provided if not (dataset_url and dataset_name and username): raise (Exception("""You should provide a file id, name and user""")) response = requests.get(dataset_url) dataset_path = "{}/{}".format(username, dataset_name) if response.status_code == 200: gc.add_file(dataset_path, response.content) dataset_definition = gc.load(dataset_path, dataset_path) return jsonify(dataset_definition) else: raise (Exception( "The dataset with URI {} could not be retrieved from the Web". format(dataset_url))) return jsonify(dataset_definition)
def web_definition(): """ Get dataset metadata from a URL Loads the metadata for a file specified by the url and name parameters. Response is the same as for `/dataset/definition` --- parameters: - name: name in: query description: The name of the dataset file that is to be loaded required: false type: string defaultValue: "Mortality.monthly_MadrasIndia.1916_1921.tab" - name: url in: query description: The URL address of the file that is to be loaded required: false type: string defaultValue: "http://example.com/interesting/file.csv" tags: - Dataverse responses: '200': description: Dataset metadata retrieved schema: $ref: "#/definitions/DatasetSchema" default: description: Unexpected error schema: $ref: "#/definitions/Message" """ dataset_url = request.args.get('url', False) dataset_name = request.args.get('name', False) username = request.args.get('user', False) log.debug("Web dataset: {}/{}".format(dataset_url, dataset_name)) # Check whether a file has been provided if not(dataset_url and dataset_name and username): raise(Exception("""You should provide a file id, name and user""")) response = requests.get(dataset_url) dataset_path = "{}/{}".format(username, dataset_name) if response.status_code == 200: gc.add_file(dataset_path, response.content) dataset_definition = gc.load(dataset_path, dataset_path) return jsonify(dataset_definition) else: raise(Exception("The dataset with URI {} could not be retrieved from the Web".format(dataset_url))) return jsonify(dataset_definition)
def dataverse_definition(): """ Get dataset metadata from a dataverse file Loads the metadata for a dataverse file specified by the id and name parameters. Response is the same as for `/dataset/definition` --- parameters: - name: name in: query description: The name of the dataset file that is to be loaded required: false type: string defaultValue: "Mortality.monthly_MadrasIndia.1916_1921.tab" - name: id in: query description: The id of a dataverse dataset file that is to be loaded required: false type: string defaultValue: 2531997 - name: user in: query description: The email address of the Google user id required: true type: string tags: - Dataverse responses: '200': description: Dataset metadata retrieved schema: $ref: "#/definitions/DatasetSchema" default: description: Unexpected error schema: $ref: "#/definitions/Message" """ dataset_id = request.args.get('id', False) dataset_name = request.args.get('name', False) username = request.args.get('user', False) log.debug("Dataverse dataset: {}/{}".format(dataset_id, dataset_name)) # Check whether a file has been provided if not (dataset_id and dataset_name and username): raise (Exception("""You should provide a file id, name and user""")) dataset_url = dc.Connection().get_access_url(dataset_id) log.debug("Dataverse url: {}".format(dataset_url)) response = requests.get(dataset_url) dataset_path = "{}/{}".format(username, dataset_name) log.debug(dataset_path) if response.status_code == 200: gc.add_file(dataset_path, response.content) dataset_definition = gc.load(dataset_path, dataset_path) return jsonify(dataset_definition) else: raise (Exception( "The dataset with URI {} could not be retrieved from Dataverse". format(dataset_url)))
def get_dataset_definition(): """ Get dataset metadata Loads the metadata for a dataset specified by the 'path' relative path argument. --- parameters: - name: path in: query description: The relative path of the dataset file that is to be loaded required: false type: string defaultValue: derived/utrecht_1829_clean_01.csv tags: - Dataset responses: '200': description: Dataset metadata retrieved schema: id: DatasetSchema type: object properties: name: type: string description: The name of the dataset path: type: string description: The location of the dataset on disk (server side) variables: description: A dictionary of variable names and values occurring in the dataset type: object properties: default: description: The default uri for this variable name type: string uri: description: The assigned uri for this variable name type: string label: description: The label for this variable name (i.e. the name itself) type: string description: description: The description of the variable type: string category: description: The category of the variable (coded, identifier, other, community) type: string type: description: The DataCube type of the variable (sdmx:DimensionProperty, ... etc.) type: string codelist: description: If appliccable, the codelist for this variable type: object properties: default: description: The default URI for the codelist type: string uri: description: The assigned URI for the codelist type: string label: description: The label for the codelist type: string values: description: An array with values and frequencies for this variable name additionalProperties: description: The values and frequencies for this variable schema: type: object items: type: object default: description: The default URI representation for this value type: string uri: description: The assigned URI representation for this value type: string label: description: The value as a label type: string literal: description: The assigned Literal representation for this value count: type: integer format: int32 required: - name - path - mappings - values default: description: Unexpected error schema: $ref: "#/definitions/Message" """ dataset_path = request.args.get('path', False) # Check whether a file path has been provided if not dataset_path: raise (Exception("""You should provide a relative path to the file you want to load, and specify its name""")) dataset_name = os.path.basename(dataset_path) # DEPRECATED: Create an absolute path # absolute_dataset_path = os.path.join(config.TEMP_PATH, dataset_path) log.debug('Dataset path: ' + dataset_path) dataset_definition = gc.load(dataset_name, dataset_path) return jsonify(dataset_definition)
def dataverse_definition(): """ Get dataset metadata from a dataverse file Loads the metadata for a dataverse file specified by the id and name parameters. Response is the same as for `/dataset/definition` --- parameters: - name: name in: query description: The name of the dataset file that is to be loaded required: false type: string defaultValue: "Mortality.monthly_MadrasIndia.1916_1921.tab" - name: id in: query description: The id of a dataverse dataset file that is to be loaded required: false type: string defaultValue: 2531997 - name: user in: query description: The email address of the Google user id required: true type: string tags: - Dataverse responses: '200': description: Dataset metadata retrieved schema: $ref: "#/definitions/DatasetSchema" default: description: Unexpected error schema: $ref: "#/definitions/Message" """ dataset_id = request.args.get('id', False) dataset_name = request.args.get('name', False) username = request.args.get('user', False) log.debug("Dataverse dataset: {}/{}".format(dataset_id, dataset_name)) # Check whether a file has been provided if not(dataset_id and dataset_name and username): raise(Exception("""You should provide a file id, name and user""")) dataset_url = dc.Connection().get_access_url(dataset_id) log.debug("Dataverse url: {}".format(dataset_url)) response = requests.get(dataset_url) dataset_path = "{}/{}".format(username, dataset_name) log.debug(dataset_path) if response.status_code == 200: gc.add_file(dataset_path, response.content) dataset_definition = gc.load(dataset_path, dataset_path) return jsonify(dataset_definition) else: raise(Exception("The dataset with URI {} could not be retrieved from Dataverse".format(dataset_url)))
def get_dataset_definition(): """ Get dataset metadata Loads the metadata for a dataset specified by the 'path' relative path argument. --- parameters: - name: path in: query description: The relative path of the dataset file that is to be loaded required: false type: string defaultValue: derived/utrecht_1829_clean_01.csv tags: - Dataset responses: '200': description: Dataset metadata retrieved schema: id: DatasetSchema type: object properties: name: type: string description: The name of the dataset path: type: string description: The location of the dataset on disk (server side) variables: description: A dictionary of variable names and values occurring in the dataset type: object properties: default: description: The default uri for this variable name type: string uri: description: The assigned uri for this variable name type: string label: description: The label for this variable name (i.e. the name itself) type: string description: description: The description of the variable type: string category: description: The category of the variable (coded, identifier, other, community) type: string type: description: The DataCube type of the variable (sdmx:DimensionProperty, ... etc.) type: string codelist: description: If appliccable, the codelist for this variable type: object properties: default: description: The default URI for the codelist type: string uri: description: The assigned URI for the codelist type: string label: description: The label for the codelist type: string values: description: An array with values and frequencies for this variable name additionalProperties: description: The values and frequencies for this variable schema: type: object items: type: object default: description: The default URI representation for this value type: string uri: description: The assigned URI representation for this value type: string label: description: The value as a label type: string literal: description: The assigned Literal representation for this value count: type: integer format: int32 required: - name - path - mappings - values default: description: Unexpected error schema: $ref: "#/definitions/Message" """ dataset_path = request.args.get('path', False) # Check whether a file path has been provided if not dataset_path: raise(Exception("""You should provide a relative path to the file you want to load, and specify its name""")) dataset_name = os.path.basename(dataset_path) # DEPRECATED: Create an absolute path # absolute_dataset_path = os.path.join(config.TEMP_PATH, dataset_path) log.debug('Dataset path: ' + dataset_path) dataset_definition = gc.load(dataset_name, dataset_path) return jsonify(dataset_definition)