Пример #1
0
def main(argv):

    recID=0
    opts,pargs=getopt.getopt(argv,'di:')
    verbose = False
    for opt, arg in opts:

        if opt == '-i':
            recID=arg
        if opt == '-d':
            verbose = True

    result=format_record(recID=recID,of='xm')

    if result:
	    #change the result to MARC by applying a template
            if verbose:
                print result
                raw_input("go on?")
	    result = bibconvert_xslt_engine.convert(result, "marcxmltoplain.xsl")
            #call a sub that changes the stuff to editable form, calls editor,
	    #returns a string
	    new = convert_edit(result)
	    newr = to_marc(new)
            if verbose:
                #debug
                f=open('/tmp/debug', 'w')
                f.write(new)
                f.write(newr)
                f.close()
                print newr
	    if upper(raw_input("Save to DB Y/N:")) =='Y':
        	 recs=xml_marc_to_records(''.join(newr))
	         response=bibupload(recs[0],opt_mode='replace')
	         if response[0]:print "Error updating record: "+response[0]
Пример #2
0
def main(argv):

    recID=0
    opts,pargs=getopt.getopt(argv,'di:')
    verbose = False
    for opt, arg in opts:

        if opt == '-i':
            recID=arg
        if opt == '-d':
            verbose = True

    result=format_record(recID=recID,of='xm')

    if result:
	    #change the result to MARC by applying a template
            if verbose:
                print result
                raw_input("go on?")
	    result = bibconvert_xslt_engine.convert(result, "marcxmltoplain.xsl")
            #call a sub that changes the stuff to editable form, calls editor,
	    #returns a string
	    new = convert_edit(result)
	    newr = to_marc(new)
            if verbose:
                #debug
                f=open('/tmp/debug', 'w')
                f.write(new)
                f.write(newr)
                f.close()
                print newr
	    if upper(raw_input("Save to DB Y/N:")) =='Y':
        	 recs=xml_marc_to_records(''.join(newr))
	         response=bibupload(recs[0],opt_mode='replace')
	         if response[0]:print "Error updating record: "+response[0]
Пример #3
0
    def _convert_record(obj, eng):
        """
        Will convert the object data, if XML, using the given stylesheet
        """
        from invenio.bibconvert_xslt_engine import convert

        obj.extra_data["last_task_name"] = 'Convert Record'
        eng.log_info("Starting conversion using %s stylesheet" %
                     (stylesheet,))
        eng.log_info("Type of data: %s" % (obj.data_type,))
        try:
            obj.data = convert(obj.data, stylesheet)
        except:
            obj.extra_data["error_msg"] = 'Could not convert record'
            eng.log_error("Error: %s" % (obj.extra_data["error_msg"],))
            raise
Пример #4
0
    def _convert_record(obj, eng):
        """
        Will convert the object data, if XML, using the given stylesheet
        """
        from invenio.bibconvert_xslt_engine import convert

        obj.db_obj.last_task_name = 'convert_record'
        eng.log.info("Starting conversion using %s stylesheet" %
                     (stylesheet, ))
        eng.log.info("Type of data: %s" % (obj.db_obj.data_type, ))
        if obj.db_obj.data_type == "text/xml":
            try:
                obj.data['data'] = convert(obj.data['data'], stylesheet)
            except:
                obj.error_msg = 'Could not convert record'
                eng.log.error("Error: %s" % (obj.db_obj.error_msg, ))
                raise
        else:
            eng.halt("Data type not valid text/xml")
Пример #5
0
def get_marcxml_for_doi(doi):
    """
    Send doi to the http://www.crossref.org/openurl page.
    Attaches parameters: username, password, doi and noredirect.
    Returns the MARCXML code or throws an exception, when
    1. DOI is malformed
    2. Record not found
    """
    if not CFG_CROSSREF_USERNAME and not CFG_CROSSREF_PASSWORD:
        raise CrossrefError("error_crossref_no_account")

    # Clean the DOI
    doi = doi.strip()

    # No Need for the  ":" if no password
    if  CFG_CROSSREF_PASSWORD: 
        query = CFG_CROSSREF_USERNAME + ":" + CFG_CROSSREF_PASSWORD + "&noredirect=tru&id=doi:" + doi
    else:
        query = CFG_CROSSREF_USERNAME +  "&noredirect=tru&id=doi:" + doi

    # Getting the data from external source
    url = "http://www.crossref.org/openurl/?pid=" + query 
    request = urllib2.Request(url)
    response = CROSSREF_OPENER.open(request)
    header = response.info().getheader('Content-Type')
    content = response.read()

    # Check if the returned page is html - this means the DOI is malformed
    if "text/html" in header:
        raise CrossrefError("error_crossref_malformed_doi")
    if 'status="unresolved"' in content:
        raise CrossrefError("error_crossref_record_not_found")

    # Convert xml to marc using convert function
    # from bibconvert_xslt_engine file
    # Seting the path to xsl template
    xsl_crossref2marc_config = "%s/bibconvert/config/%s" % \
    (CFG_ETCDIR, "crossref2marcxml.xsl")

    output = convert(xmltext=content, \
                    template_filename=xsl_crossref2marc_config)
    return output
Пример #6
0
def get_marcxml_for_doi(doi):
    """
    Send doi to the http://www.crossref.org/openurl page.
    Attaches parameters: username, password, doi and noredirect.
    Returns the MARCXML code or throws an exception, when
    1. DOI is malformed
    2. Record not found
    """
    if not CFG_CROSSREF_USERNAME and not CFG_CROSSREF_PASSWORD:
        raise CrossrefError("error_crossref_no_account")

    # Clean the DOI
    doi = doi.strip()

    # No Need for the  ":" if no password
    if CFG_CROSSREF_PASSWORD:
        query = CFG_CROSSREF_USERNAME + ":" + CFG_CROSSREF_PASSWORD + "&noredirect=tru&id=doi:" + doi
    else:
        query = CFG_CROSSREF_USERNAME + "&noredirect=tru&id=doi:" + doi

    # Getting the data from external source
    url = "http://www.crossref.org/openurl/?pid=" + query
    request = urllib2.Request(url)
    response = CROSSREF_OPENER.open(request)
    header = response.info().getheader('Content-Type')
    content = response.read()

    # Check if the returned page is html - this means the DOI is malformed
    if "text/html" in header:
        raise CrossrefError("error_crossref_malformed_doi")
    if 'status="unresolved"' in content:
        raise CrossrefError("error_crossref_record_not_found")

    # Convert xml to marc using convert function
    # from bibconvert_xslt_engine file
    # Seting the path to xsl template
    xsl_crossref2marc_config = "%s/bibconvert/config/%s" % \
    (CFG_ETCDIR, "crossref2marcxml.xsl")

    output = convert(xmltext=content, \
                    template_filename=xsl_crossref2marc_config)
    return output