예제 #1
0
파일: xslt.py 프로젝트: mhellmic/b2share
def get_creation_date_lxml(ctx, recID, fmt="%Y-%m-%dT%H:%M:%SZ"):
    """
    libxslt extension function:
    Bridge between BibFormat and XSL stylesheets.
    Returns record creation date.

    Can be used in that way in XSL stylesheet
    (provided xmlns:fn="http://cdsweb.cern.ch/bibformat/fn" has been declared):
    <xsl:value-of select="fn:creation_date(445)"/> where 445 is a recID

    if recID is string, value is converted to int
    if recID is Node, first child node (text node) is taken as value

    @param ctx: context as passed by lxml
    @param recID: record ID
    @param fmt: format of the returned date
    @return: creation date of X{recID}
    @rtype: string
    """
    try:
        if isinstance(recID, str):
            recID_int = int(recID)
        elif isinstance(recID, (int, long)):
            recID_int = recID
        elif isinstance(recID, list):
            recID = recID[0]
            if isinstance(recID, str):
                recID_int = int(recID)
            else:
                recID_int = int(recID.text)
        else:
            recID_int = int(recID.text)

        if isinstance(fmt, str):
            fmt_str = fmt
        elif isinstance(fmt, list):
            fmt = fmt[0]
            if isinstance(fmt, str):
                fmt_str = fmt
            else:
                fmt_str = fmt.text
        else:
            fmt_str = fmt.text

        return get_creation_date(recID_int, fmt_str)
    except Exception as err:
        sys.stderr.write("Error during formatting function evaluation: " + \
                         str(err) + \
                         '\n')

        return ''
예제 #2
0
파일: xslt.py 프로젝트: SCOAP3/invenio
def _get_creation_date(ctx, recID, fmt="%Y-%m-%dT%H:%M:%SZ"):
    """
    Bridge between BibFormat and XSL stylesheets.

    Can be used in that way in XSL stylesheet (provided
    ``xmlns:fn="http://cdsweb.cern.ch/bibformat/fn"`` has been declared):
    ``<xsl:value-of select="fn:creation_date(445)"/>`` where 445 is a recID

    if recID is string, value is converted to int
    if recID is Node, first child node (text node) is taken as value

    :param ctx: context as passed by lxml
    :param recID: record ID
    :param fmt: format of the returned date
    :return: creation date of X{recID}
    :rtype: str

    """
    try:
        if isinstance(recID, str):
            recID_int = int(recID)
        elif isinstance(recID, (int, long)):
            recID_int = recID
        elif isinstance(recID, list):
            recID = recID[0]
            if isinstance(recID, str):
                recID_int = int(recID)
            else:
                recID_int = int(recID.text)
        else:
            recID_int = int(recID.text)

        if isinstance(fmt, str):
            fmt_str = fmt
        elif isinstance(fmt, list):
            fmt = fmt[0]
            if isinstance(fmt, str):
                fmt_str = fmt
            else:
                fmt_str = fmt.text
        else:
            fmt_str = fmt.text

        return get_creation_date(recID_int, fmt_str)
    except Exception:
        current_app.logger.exception(
            "Error during formatting function evaluation"
        )
        return ''
예제 #3
0
파일: xslt.py 프로젝트: chokribr/invenio-1
def _get_creation_date(ctx, recID, fmt="%Y-%m-%dT%H:%M:%SZ"):
    """
    Bridge between BibFormat and XSL stylesheets.

    Can be used in that way in XSL stylesheet (provided
    ``xmlns:fn="http://cdsweb.cern.ch/bibformat/fn"`` has been declared):
    ``<xsl:value-of select="fn:creation_date(445)"/>`` where 445 is a recID

    if recID is string, value is converted to int
    if recID is Node, first child node (text node) is taken as value

    :param ctx: context as passed by lxml
    :param recID: record ID
    :param fmt: format of the returned date
    :return: creation date of X{recID}
    :rtype: str

    """
    try:
        if isinstance(recID, str):
            recID_int = int(recID)
        elif isinstance(recID, (int, long)):
            recID_int = recID
        elif isinstance(recID, list):
            recID = recID[0]
            if isinstance(recID, str):
                recID_int = int(recID)
            else:
                recID_int = int(recID.text)
        else:
            recID_int = int(recID.text)

        if isinstance(fmt, str):
            fmt_str = fmt
        elif isinstance(fmt, list):
            fmt = fmt[0]
            if isinstance(fmt, str):
                fmt_str = fmt
            else:
                fmt_str = fmt.text
        else:
            fmt_str = fmt.text

        return get_creation_date(recID_int, fmt_str)
    except Exception:
        current_app.logger.exception(
            "Error during formatting function evaluation")
        return ''
예제 #4
0
파일: xslt.py 프로젝트: mhellmic/b2share
def get_creation_date_4suite(ctx, recID, fmt="%Y-%m-%dT%H:%M:%SZ"):
    """
    4suite extension function:
    Bridge between BibFormat and XSL stylesheets.
    Returns record creation date.

    Can be used in that way in XSL stylesheet
    (provided xmlns:fn="http://cdsweb.cern.ch/bibformat/fn" has been declared):
    <xsl:value-of select="fn:creation_date(445)"/>

    if value is int, value is converted to string
    if value is Node, first child node (text node) is taken as value

    @param ctx: context as passed by 4suite
    @param recID: record ID
    @param fmt: format of the returned date
    @return: creation date of X{recID}
    @rtype: string
    """
    try:
        if len(recID) > 0 and isinstance(recID[0], Node):
            recID_int = recID[0].firstChild.nodeValue
            if recID_int is None:
                return ''
        else:
            recID_int = int(recID)

        if len(fmt) > 0 and isinstance(fmt[0], Node):
            fmt_str = fmt[0].firstChild.nodeValue
            if fmt_str is None:
                fmt_str = "%Y-%m-%dT%H:%M:%SZ"
        else:
            fmt_str = str(fmt)

        return get_creation_date(recID_int, fmt_str)
    except Exception as err:
        sys.stderr.write("Error during formatting function evaluation: " + \
                         str(err) + \
                         '\n')

        return ''
예제 #5
0
파일: views.py 프로젝트: rsalas82/lw-daap
def dcat():
    from invenio.legacy.search_engine import perform_request_search
    from invenio.modules.records.api import get_record
    from invenio.modules.formatter.api import get_modification_date, get_creation_date
    from invenio.utils.mimetype import guess_mimetype_and_encoding, guess_extension

    recids = perform_request_search(cc='Dataset')
    dcat =     """<rdf:RDF\n"""
    dcat +=    """   xmlns:dc="http://purl.org/dc/elements/1.1/"\n"""
    dcat +=    """   xmlns:dcat="http://www.w3.org/ns/dcat#"\n"""
    dcat +=    """   xmlns:dct="http://purl.org/dc/terms/"\n"""
    dcat +=    """   xmlns:foaf="http://xmlns.com/foaf/0.1/"\n"""
    dcat +=    """   xmlns:xsd="http://www.w3.org/2001/XMLSchema#"\n"""
    dcat +=    """   xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"\n"""
    dcat +=    """   xmlns:owl="http://www.w3.org/2002/07/owl#"\n"""
    dcat +=    """   xmlns:time="http://www.w3.org/2006/time#"\n"""
    dcat +=    """   xmlns:prism="http://prismstandard.org/namespaces/basic/3.0/"\n"""
    dcat +=    """   xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">\n"""
    dcat +=    """      <dcat:Catalog rdf:about=\"""" + current_app.config['CFG_SITE_URL'] + """/collection/Dataset">\n"""
    dcat +=    """         <dc:language>""" + current_app.config['CFG_SITE_LANG'] + """</dc:language>\n"""
    dcat +=    """         <dct:title xml:lang=\"""" + current_app.config['CFG_SITE_LANG'] + """\">""" + current_app.config['CFG_SITE_NAME'] + """</dct:title>\n"""
    if current_app.config['CFG_SITE_DESCRIPTION']:
        dcat +=    """         <dct:description xml:lang=\"""" + current_app.config['CFG_SITE_LANG'] + """\">""" + current_app.config['CFG_SITE_DESCRIPTION'] + """</dct:description>\n"""
    else:
        dcat +=    """         <dct:description xml:lang=\"""" + current_app.config['CFG_SITE_LANG'] + """\">""" + current_app.config['CFG_SITE_NAME'] + """</dct:description>\n"""
    dcat +=    """         <dct:extent>\n"""
    dcat +=    """            <dct:SizeOrDuration>\n"""
    dcat +=    """               <rdf:value rdf:datatype="http://www.w3.org/2001/XMLSchema#nonNegativeInteger">""" + str(len(recids)) + """</rdf:value>\n"""
    dcat +=    """                  <rdfs:label xml:lang=\"""" + current_app.config['CFG_SITE_LANG'] + """\">""" + str(len(recids)) + """ datasets</rdfs:label>\n"""
    dcat +=    """            </dct:SizeOrDuration>\n"""
    dcat +=    """         </dct:extent>\n"""
    dcat +=    """         <foaf:homepage rdf:resource=\"""" + current_app.config['CFG_SITE_URL'] + """\"/>\n"""
    dcat +=    """         <dct:publisher rdf:resource="http://www.lifewatch.eu/"/>\n"""
    dcat +=    """         <dcat:themeTaxonomy rdf:resource="http://datos.gob.es/kos/sector-publico/sector/medio-rural-pesca"/>\n"""
    dcat +=    """         <dcat:themeTaxonomy rdf:resource="http://datos.gob.es/kos/sector-publico/sector/medio-ambiente"/>\n"""

    issues = []
    modifications = []
    for recid in recids:
        issues.append(get_creation_date(recid))
        modifications.append(get_modification_date(recid))

    dcat +=    """         <dct:issued rdf:datatype="http://www.w3.org/2001/XMLSchema#dateTime">""" + str(min(issues)) + """</dct:issued>\n"""
    dcat +=    """         <dct:modified rdf:datatype="http://www.w3.org/2001/XMLSchema#dateTime">""" + str(max(modifications)) + """</dct:modified>\n"""

    for recid in recids:
        record = get_record(recid)
        dcat += """         <dcat:dataset>\n"""
        if 'doi' in record:
            dcat += """            <dcat:Dataset rdf:about="http://dx.doi.org/""" + str(record['doi']) + """\">\n"""
            dcat += """               <dct:identifier>http://dx.doi.org/""" + str(record['doi']) + """</dct:identifier>\n"""
        else:
            dcat += """            <dcat:Dataset rdf:about=\"""" + current_app.config['CFG_SITE_URL'] + """/""" + current_app.config['CFG_SITE_RECORD'] + """/""" + str(recid) + """">\n"""
            dcat += """               <dct:identifier>""" + current_app.config['CFG_SITE_URL'] + """/""" + current_app.config['CFG_SITE_RECORD'] + """/""" + str(recid) + """     </dct:identifier>\n"""
        dcat += """               <dct:title xml:lang=\"""" + current_app.config['CFG_SITE_LANG'] + """\">""" + str(record['title']) + """</dct:title>\n"""
        dcat += """               <dct:description xml:lang=\"""" + current_app.config['CFG_SITE_LANG'] + """\">""" + str(record['description']) + """</dct:description>\n"""
        dcat += """               <dcat:theme rdf:resource="http://datos.gob.es/kos/sector-publico/sector/ciencia-tecnologia"/>\n"""
        dcat += """               <dc:language>""" + current_app.config['CFG_SITE_LANG'] + """</dc:language>\n"""
        dcat += """               <dct:publisher rdf:resource="http://www.lifewatch.eu/"/>\n"""
        if record['access_right'] <> 'restricted' and record['access_right'] <> 'closed':
            if 'url' in record['__license_text__']:
                dcat += """               <dct:license rdf:resource=\"""" + str((record['__license_text__'])['url']) + """\"/>\n"""
            if 'embargo_date' in record:
                dcat += """               <prism:embargoDate rdf:datatype="http://www.w3.org/2001/XMLSchema/#date">""" + str(record['embargo_date']) + """</prism:embargoDate>\n"""
        for kw in record['keywords']:
            dcat += """               <dcat:keyword>""" + str(kw) + """</dcat:keyword>\n"""
        dcat += """               <dct:issued rdf:datatype="http://www.w3.org/2001/XMLSchema#date">""" + str(get_creation_date(recid)) + """</dct:issued>\n"""
        dcat += """               <dct:modified rdf:datatype="http://www.w3.org/2001/XMLSchema#date">""" + str(get_modification_date(recid)) + """</dct:modified>\n"""
        if 'period' in record:
            for period in record['period']:
                dcat += """               <dct:temporal>\n"""
                dcat += """                  <time:Interval>\n"""
                dcat += """                     <rdf:type rdf:resource="http://purl.org/dc/terms/PeriodOfTime" />\n"""
                dcat += """                     <time:hasBeginning>\n"""
                dcat += """                        <time:Instant>\n"""
                dcat += """                           <time:inXSDDateTime rdf:datatype="http://www.w3.org/2001/XMLSchema#dateTime">""" + str(period['start']) + """</time:inXSDDateTime>\n"""
                dcat += """                           </time:inXSDDateTime>\n"""
                dcat += """                        </time:Instant>\n"""
                dcat += """                     </time:hasBeginning>\n"""
                dcat += """                     <time:hasEnd>\n"""
                dcat += """                        <time:Instant>\n"""
                dcat += """                           <time:inXSDDateTime rdf:datatype="http://www.w3.org/2001/XMLSchema#dateTime">""" + str(period['end']) + """</time:inXSDDateTime>\n"""
                dcat += """                        </time:Instant>\n"""
                dcat += """                     </time:hasEnd>\n"""
                dcat += """                  </time:Interval>\n"""
                dcat += """               </dct:temporal>\n"""
        if 'spatial' in record:
            for spatial in record['spatial']:
                dcat += """               <dct:spatial>\n"""
                dcat += """                  <dct:Location>\n"""
                dcat += """                      <locn:geometry rdf:datatype="https://www.iana.org/assignments/media-types/application/vnd.geo+json">\n"""
                dcat += """                          {"type": "Polygon", "coordinates": [[[""" + str(spatial['north']) + """), """ + str(spatial['west']) + """], [""" + str(spatial['north']) + """, """ + str(spatial['east']) + """], [""" + str(spatial['south']) + """, """ + str(spatial['east']) + """], [""" + str(spatial['south']) + """, """ + str(spatial['west']) + """], [""" + str(spatial['north']) + """, """ + str(spatial['west']) + """]]]}\n"""
                dcat += """                      </locn:geometry>\n"""
                dcat += """                  </dct:Location>\n"""
                dcat += """               </dct:spatial>\n"""
        if 'frequency' in record:
            for frequency in record['frequency']:
                dcat += """               <dct:accrualPeriodicity>\n"""
                dcat += """                  <dct:Frequency>\n"""
                dcat += """                      <rdfs:label>Every """ + str(frequency['size']) + """ """ + str(frequency['unit']) + """s</rdfs:label>\n"""
                dcat += """                      <rdf:value>\n"""
                dcat += """                          <time:DurationDescription>\n"""
                dcat += """                              <rdfs:label>""" + str(frequency['size']) + """ """ + str(frequency['unit']) + """s</rdfs:label>\n"""
                dcat += """                              <time:""" + str(frequency['unit']) + """s rdf:datatype="http://www.w3.org/2001/XMLSchema#decimal">""" +  str(frequency['size']) + """</time:""" + str(frequency['unit']) + """s>\n"""
                dcat += """                          </time:DurationDescription>\n"""
                dcat += """                      </rdf:value>\n"""
                dcat += """                  </dct:Frequency>\n"""
                dcat += """               </dct:accrualPeriodicity>\n"""
        if 'related_identifiers' in record:
            for reference in record['related_identifiers']:
                dcat += """               <dct:references rdf:resource="http://dx.doi.org/""" + str(reference['identifier']) + """"/>\n"""
        if 'fft' in record:
            for dis in record['fft']:
                dcat += """               <dcat:distribution>\n"""
                dcat += """                  <dcat:Distribution>\n"""
                if 'description' in dis:
                    dcat += """                     <dct:title xml:lang="en">""" + str(dis['description']) + """</dct:title>\n"""
                dcat += """                     <dct:accessURL  rdf:datatype="http://www.w3.org/2001/XMLSchema#anyURI">""" + str(dis['url']) + """</dct:accessURL>\n"""
                dcat += """                     <dct:format>\n"""
                mimetype = str(guess_mimetype_and_encoding(dis['url'])[0])
                dcat += """                        <dct:IMT rdf:value=\"""" + mimetype + """\" rdfs:label=\"""" + str(guess_extension(mimetype)[1:]).upper() + """\"/>\n"""
                dcat += """                     </dct:format>\n"""
                dcat += """                     <dcat:byteSize rdf:datatype="http://www.w3.org/2001/XMLSchema#integer">""" + str(dis['file_size']) + """</dcat:byteSize>\n"""
                dcat += """                  </dcat:Distribution>\n"""
                dcat += """               </dcat:distribution>\n"""
        dcat += """            </dcat:Dataset>\n"""
        dcat += """         </dcat:dataset>\n"""
    dcat += """      </dcat:Catalog>\n"""
    dcat += """</rdf:RDF>"""

    response = make_response(dcat)
    response.headers["Content-Disposition"] = "attachment; filename=dcat.rdf"
    return response
예제 #6
0
파일: views.py 프로젝트: IFCA/lifewatch_osf
def dcat():
    from invenio.legacy.search_engine import perform_request_search
    from invenio.modules.records.api import get_record
    from invenio.modules.formatter.api import get_modification_date, get_creation_date
    from invenio.utils.mimetype import guess_mimetype_and_encoding, guess_extension

    recids = perform_request_search(cc='Dataset')
    dcat = """<rdf:RDF\n"""
    dcat += """   xmlns:dc="http://purl.org/dc/elements/1.1/"\n"""
    dcat += """   xmlns:dcat="http://www.w3.org/ns/dcat#"\n"""
    dcat += """   xmlns:dct="http://purl.org/dc/terms/"\n"""
    dcat += """   xmlns:foaf="http://xmlns.com/foaf/0.1/"\n"""
    dcat += """   xmlns:xsd="http://www.w3.org/2001/XMLSchema#"\n"""
    dcat += """   xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"\n"""
    dcat += """   xmlns:owl="http://www.w3.org/2002/07/owl#"\n"""
    dcat += """   xmlns:time="http://www.w3.org/2006/time#"\n"""
    dcat += """   xmlns:prism="http://prismstandard.org/namespaces/basic/3.0/"\n"""
    dcat += """   xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">\n"""
    dcat += """      <dcat:Catalog rdf:about=\"""" + current_app.config[
        'CFG_SITE_URL'] + """/collection/Dataset">\n"""
    dcat += """         <dc:language>""" + current_app.config[
        'CFG_SITE_LANG'] + """</dc:language>\n"""
    dcat += """         <dct:title xml:lang=\"""" + current_app.config[
        'CFG_SITE_LANG'] + """\">""" + current_app.config[
            'CFG_SITE_NAME'] + """</dct:title>\n"""
    if current_app.config['CFG_SITE_DESCRIPTION']:
        dcat += """         <dct:description xml:lang=\"""" + current_app.config[
            'CFG_SITE_LANG'] + """\">""" + current_app.config[
                'CFG_SITE_DESCRIPTION'] + """</dct:description>\n"""
    else:
        dcat += """         <dct:description xml:lang=\"""" + current_app.config[
            'CFG_SITE_LANG'] + """\">""" + current_app.config[
                'CFG_SITE_NAME'] + """</dct:description>\n"""
    dcat += """         <dct:extent>\n"""
    dcat += """            <dct:SizeOrDuration>\n"""
    dcat += """               <rdf:value rdf:datatype="http://www.w3.org/2001/XMLSchema#nonNegativeInteger">""" + str(
        len(recids)) + """</rdf:value>\n"""
    dcat += """                  <rdfs:label xml:lang=\"""" + current_app.config[
        'CFG_SITE_LANG'] + """\">""" + str(
            len(recids)) + """ datasets</rdfs:label>\n"""
    dcat += """            </dct:SizeOrDuration>\n"""
    dcat += """         </dct:extent>\n"""
    dcat += """         <foaf:homepage rdf:resource=\"""" + current_app.config[
        'CFG_SITE_URL'] + """\"/>\n"""
    dcat += """         <dct:publisher rdf:resource="http://www.lifewatch.eu/"/>\n"""
    dcat += """         <dcat:themeTaxonomy rdf:resource="http://datos.gob.es/kos/sector-publico/sector/medio-rural-pesca"/>\n"""
    dcat += """         <dcat:themeTaxonomy rdf:resource="http://datos.gob.es/kos/sector-publico/sector/medio-ambiente"/>\n"""

    issues = []
    modifications = []
    for recid in recids:
        issues.append(get_creation_date(recid))
        modifications.append(get_modification_date(recid))

    dcat += """         <dct:issued rdf:datatype="http://www.w3.org/2001/XMLSchema#dateTime">""" + str(
        min(issues)) + """</dct:issued>\n"""
    dcat += """         <dct:modified rdf:datatype="http://www.w3.org/2001/XMLSchema#dateTime">""" + str(
        max(modifications)) + """</dct:modified>\n"""

    for recid in recids:
        record = get_record(recid)
        dcat += """         <dcat:dataset>\n"""
        if 'doi' in record:
            dcat += """            <dcat:Dataset rdf:about="http://dx.doi.org/""" + str(
                record['doi']) + """\">\n"""
            dcat += """               <dct:identifier>http://dx.doi.org/""" + str(
                record['doi']) + """</dct:identifier>\n"""
        else:
            dcat += """            <dcat:Dataset rdf:about=\"""" + current_app.config[
                'CFG_SITE_URL'] + """/""" + current_app.config[
                    'CFG_SITE_RECORD'] + """/""" + str(recid) + """">\n"""
            dcat += """               <dct:identifier>""" + current_app.config[
                'CFG_SITE_URL'] + """/""" + current_app.config[
                    'CFG_SITE_RECORD'] + """/""" + str(
                        recid) + """     </dct:identifier>\n"""
        dcat += """               <dct:title xml:lang=\"""" + current_app.config[
            'CFG_SITE_LANG'] + """\">""" + str(
                record['title']) + """</dct:title>\n"""
        dcat += """               <dct:description xml:lang=\"""" + current_app.config[
            'CFG_SITE_LANG'] + """\">""" + str(
                record['description']) + """</dct:description>\n"""
        dcat += """               <dcat:theme rdf:resource="http://datos.gob.es/kos/sector-publico/sector/ciencia-tecnologia"/>\n"""
        dcat += """               <dc:language>""" + current_app.config[
            'CFG_SITE_LANG'] + """</dc:language>\n"""
        dcat += """               <dct:publisher rdf:resource="http://www.lifewatch.eu/"/>\n"""
        if record['access_right'] <> 'restricted' and record[
                'access_right'] <> 'closed':
            if 'url' in record['__license_text__']:
                dcat += """               <dct:license rdf:resource=\"""" + str(
                    (record['__license_text__'])['url']) + """\"/>\n"""
            if 'embargo_date' in record:
                dcat += """               <prism:embargoDate rdf:datatype="http://www.w3.org/2001/XMLSchema/#date">""" + str(
                    record['embargo_date']) + """</prism:embargoDate>\n"""
        for kw in record['keywords']:
            dcat += """               <dcat:keyword>""" + str(
                kw) + """</dcat:keyword>\n"""
        dcat += """               <dct:issued rdf:datatype="http://www.w3.org/2001/XMLSchema#date">""" + str(
            get_creation_date(recid)) + """</dct:issued>\n"""
        dcat += """               <dct:modified rdf:datatype="http://www.w3.org/2001/XMLSchema#date">""" + str(
            get_modification_date(recid)) + """</dct:modified>\n"""
        if 'period' in record:
            for period in record['period']:
                dcat += """               <dct:temporal>\n"""
                dcat += """                  <time:Interval>\n"""
                dcat += """                     <rdf:type rdf:resource="http://purl.org/dc/terms/PeriodOfTime" />\n"""
                dcat += """                     <time:hasBeginning>\n"""
                dcat += """                        <time:Instant>\n"""
                dcat += """                           <time:inXSDDateTime rdf:datatype="http://www.w3.org/2001/XMLSchema#dateTime">""" + str(
                    period['start']) + """</time:inXSDDateTime>\n"""
                dcat += """                           </time:inXSDDateTime>\n"""
                dcat += """                        </time:Instant>\n"""
                dcat += """                     </time:hasBeginning>\n"""
                dcat += """                     <time:hasEnd>\n"""
                dcat += """                        <time:Instant>\n"""
                dcat += """                           <time:inXSDDateTime rdf:datatype="http://www.w3.org/2001/XMLSchema#dateTime">""" + str(
                    period['end']) + """</time:inXSDDateTime>\n"""
                dcat += """                        </time:Instant>\n"""
                dcat += """                     </time:hasEnd>\n"""
                dcat += """                  </time:Interval>\n"""
                dcat += """               </dct:temporal>\n"""
        if 'spatial' in record:
            for spatial in record['spatial']:
                dcat += """               <dct:spatial>\n"""
                dcat += """                  <dct:Location>\n"""
                dcat += """                      <locn:geometry rdf:datatype="https://www.iana.org/assignments/media-types/application/vnd.geo+json">\n"""
                dcat += """                          {"type": "Polygon", "coordinates": [[[""" + str(
                    spatial['north']
                ) + """), """ + str(spatial['west']) + """], [""" + str(
                    spatial['north']) + """, """ + str(
                        spatial['east']) + """], [""" + str(
                            spatial['south']) + """, """ + str(
                                spatial['east']) + """], [""" + str(
                                    spatial['south']) + """, """ + str(
                                        spatial['west']) + """], [""" + str(
                                            spatial['north']) + """, """ + str(
                                                spatial['west']) + """]]]}\n"""
                dcat += """                      </locn:geometry>\n"""
                dcat += """                  </dct:Location>\n"""
                dcat += """               </dct:spatial>\n"""
        if 'frequency' in record:
            for frequency in record['frequency']:
                dcat += """               <dct:accrualPeriodicity>\n"""
                dcat += """                  <dct:Frequency>\n"""
                dcat += """                      <rdfs:label>Every """ + str(
                    frequency['size']) + """ """ + str(
                        frequency['unit']) + """s</rdfs:label>\n"""
                dcat += """                      <rdf:value>\n"""
                dcat += """                          <time:DurationDescription>\n"""
                dcat += """                              <rdfs:label>""" + str(
                    frequency['size']) + """ """ + str(
                        frequency['unit']) + """s</rdfs:label>\n"""
                dcat += """                              <time:""" + str(
                    frequency['unit']
                ) + """s rdf:datatype="http://www.w3.org/2001/XMLSchema#decimal">""" + str(
                    frequency['size']) + """</time:""" + str(
                        frequency['unit']) + """s>\n"""
                dcat += """                          </time:DurationDescription>\n"""
                dcat += """                      </rdf:value>\n"""
                dcat += """                  </dct:Frequency>\n"""
                dcat += """               </dct:accrualPeriodicity>\n"""
        if 'related_identifiers' in record:
            for reference in record['related_identifiers']:
                dcat += """               <dct:references rdf:resource="http://dx.doi.org/""" + str(
                    reference['identifier']) + """"/>\n"""
        if 'fft' in record:
            for dis in record['fft']:
                dcat += """               <dcat:distribution>\n"""
                dcat += """                  <dcat:Distribution>\n"""
                if 'description' in dis:
                    dcat += """                     <dct:title xml:lang="en">""" + str(
                        dis['description']) + """</dct:title>\n"""
                dcat += """                     <dct:accessURL  rdf:datatype="http://www.w3.org/2001/XMLSchema#anyURI">""" + str(
                    dis['url']) + """</dct:accessURL>\n"""
                dcat += """                     <dct:format>\n"""
                mimetype = str(guess_mimetype_and_encoding(dis['url'])[0])
                dcat += """                        <dct:IMT rdf:value=\"""" + mimetype + """\" rdfs:label=\"""" + str(
                    guess_extension(mimetype)[1:]).upper() + """\"/>\n"""
                dcat += """                     </dct:format>\n"""
                dcat += """                     <dcat:byteSize rdf:datatype="http://www.w3.org/2001/XMLSchema#integer">""" + str(
                    dis['file_size']) + """</dcat:byteSize>\n"""
                dcat += """                  </dcat:Distribution>\n"""
                dcat += """               </dcat:distribution>\n"""
        dcat += """            </dcat:Dataset>\n"""
        dcat += """         </dcat:dataset>\n"""
    dcat += """      </dcat:Catalog>\n"""
    dcat += """</rdf:RDF>"""

    response = make_response(dcat)
    response.headers["Content-Disposition"] = "attachment; filename=dcat.rdf"
    return response