def doilookup(self, req, form): """ Returns the metadata from the crossref website based on the DOI. """ args = wash_urlargd(form, {'doi': (str, '')}) response = defaultdict(list) if args['doi']: doi = args['doi'] try: marcxml_template = get_marcxml_for_doi(doi) except CrossrefError: # Just ignore Crossref errors pass else: record = create_record(marcxml_template)[0] if record: # We need to convert this record structure to a simple dictionary for key, value in record.items( ): # key, value = (773, [([('0', 'PER:64142'), ...], ' ', ' ', '', 47)]) for val in value: # val = ([('0', 'PER:64142'), ...], ' ', ' ', '', 47) ind1 = val[1].replace(" ", "_") ind2 = val[2].replace(" ", "_") for (k, v) in val[0]: # k, v = ('0', 'PER:5409') response[key + ind1 + ind2 + k].append(v) # The output dictionary is something like: # {"100__a": ['Smith, J.'], # "700__a": ['Anderson, J.', 'Someoneelse, E.'], # "700__u": ['University1', 'University2']} # return dictionary as JSON return json.dumps(response)
def doilookup(self, req, form): """ Returns the metadata from the crossref website based on the DOI. """ args = wash_urlargd(form, { 'doi': (str, '')}) response = defaultdict(list) if args['doi']: doi = args['doi'] try: marcxml_template = get_marcxml_for_doi(doi) except CrossrefError: # Just ignore Crossref errors pass else: record = create_record(marcxml_template)[0] if record: # We need to convert this record structure to a simple dictionary for key, value in record.items(): # key, value = (773, [([('0', 'PER:64142'), ...], ' ', ' ', '', 47)]) for val in value: # val = ([('0', 'PER:64142'), ...], ' ', ' ', '', 47) ind1 = val[1].replace(" ", "_") ind2 = val[2].replace(" ", "_") for (k, v) in val[0]: # k, v = ('0', 'PER:5409') response[key+ind1+ind2+k].append(v) # The output dictionary is something like: # {"100__a": ['Smith, J.'], # "700__a": ['Anderson, J.', 'Someoneelse, E.'], # "700__u": ['University1', 'University2']} # return dictionary as JSON return json.dumps(response)
def get_title_of_doi(doi): try: xml = get_marcxml_for_doi(doi) except CrossrefError: return doi root = ET.fromstring(xml) for datafield in root.findall("datafield"): tag = datafield.get("tag") if tag == "245": title = datafield.find("subfield").text return title return doi
def get_title_of_doi(doi): try: xml = get_marcxml_for_doi(doi) except CrossrefError: return doi root = ET.fromstring(xml) for datafield in root.findall('datafield'): tag = datafield.get('tag') if tag == '245': title = datafield.find('subfield').text return title return doi