WSL/SLF GitLab Repository

Commit f183b888 authored by Rebecca Kurup Buchholz's avatar Rebecca Kurup Buchholz
Browse files

Worked on converter

parent e308d0d6
Pipeline #528 passed with stages
in 2 minutes and 12 seconds
import json
from urllib import request
import ssl
import collections
# Converter valid only for metadata schema of EnviDat
def envidat_to_opendataswiss_converter(metadata_record):
# WARNING: Converter valid only for metadata schema of EnviDat!
def envidat_to_opendataswiss_converter(package_list_url):
Converts JSON data to XML fil
Converts JSON data to XML file
:param metadata_record: JSON data from EnviDat metadata record from
:param package_list_url: API URL that has EnviDat metadata records data in JSON format
Package list URL:
testing with
:return: XML file in OpenDataSwiss format like this
# TODO try using call to resource_show
# TODO fix SSL certificates issue
ssl._create_default_https_context = ssl._create_unverified_context
# Assign package_list API JSON data to Python dictionary
with request.urlopen(package_list_url) as metadata:
package_list = json.load(metadata)
# Convert each record in package_list to XML format
for package in package_list['result']:
md_metadata_dict = collections.OrderedDict()
# Header
md_metadata_dict['@xmlns:dct'] = ""
md_metadata_dict['@xmlns:dc'] = ""
md_metadata_dict['@xmlns:dcat'] = ""
md_metadata_dict['@xmlns:foaf'] = ""
md_metadata_dict['@xmlns:xsd'] = ""
md_metadata_dict['@xmlns:rdfs'] = ""
md_metadata_dict['@xmlns:rdf'] = ""
md_metadata_dict['@xmlns:vcard'] = ""
md_metadata_dict['@xmlns:odrs'] = ""
md_metadata_dict['@xmlns:schema'] = ""
package_name = package['name']
md_metadata_dict['dcat:Dataset'] = {'@rdf:about': f'{package_name}'}
with open(metadata_record) as json_format_file:
# data = json.load(json_format_file)
# print(data)
# ID
package_id = package['id']
md_metadata_dict['dcat:Dataset']['dct:identifier'] = f'{package_id}@envidat'
# ========================================== TESTING ===========================================================
# envidat_to_opendataswiss_converter("")
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment