From b64e1f9133cf2757347e3e95b590ac90c7318024 Mon Sep 17 00:00:00 2001 From: Boris Ponsioen <b.g.t.ponsioen@uva.nl> Date: Mon, 16 Apr 2018 14:58:23 +0200 Subject: [PATCH] Readds error handling in get_crossref_test temporarily --- metacore/services.py | 76 ++++++++++++++++++++++---------------------- 1 file changed, 38 insertions(+), 38 deletions(-) diff --git a/metacore/services.py b/metacore/services.py index 941c66a77..ffd719628 100644 --- a/metacore/services.py +++ b/metacore/services.py @@ -74,41 +74,41 @@ def parse_crossref_citable(citable_item): return if not Citable.objects(doi=doi): - # try: - # Parse certain fields for storage on top level in document - # Blame the convoluted joining and looping on CR - - if 'reference' in citable_item: - references_with_doi = [ref for ref in citable_item['reference'] if 'DOI' in ref] - references = [ref['DOI'].lower() for ref in references_with_doi] - else: - references = [] - - authors = [] - for author_names in citable_item['author']: - author = [] - if 'given' in author_names: - author.append(author_names['given']) - if 'family' in author_names: - author.append(author_names['family']) - - authors.append(' '.join(author)) - - publisher = citable_item['publisher'] - title = citable_item['title'][0] - publication_date = '-'.join([str(date_part) for date_part in citable_item['issued']['date-parts'][0]]) - if 'license' in citable_item: - license = citable_item['license'][0]['URL'] - else: - license = '' - - return CitableWithDOI(doi=doi, references=references, authors=authors, publisher=publisher, title=title, - publication_date=publication_date, license=license, metadata=citable_item) - - # except BaseException as e: - # print("Error!") - # print(e) - # # raise - # except e: - # print("Error: ", e) - # print(citable_item) + try: + # Parse certain fields for storage on top level in document + # Blame the convoluted joining and looping on CR + + if 'reference' in citable_item: + references_with_doi = [ref for ref in citable_item['reference'] if 'DOI' in ref] + references = [ref['DOI'].lower() for ref in references_with_doi] + else: + references = [] + + authors = [] + for author_names in citable_item['author']: + author = [] + if 'given' in author_names: + author.append(author_names['given']) + if 'family' in author_names: + author.append(author_names['family']) + + authors.append(' '.join(author)) + + publisher = citable_item['publisher'] + title = citable_item['title'][0] + publication_date = '-'.join([str(date_part) for date_part in citable_item['issued']['date-parts'][0]]) + if 'license' in citable_item: + license = citable_item['license'][0]['URL'] + else: + license = '' + + return CitableWithDOI(doi=doi, references=references, authors=authors, publisher=publisher, title=title, + publication_date=publication_date, license=license, metadata=citable_item) + + # except BaseException as e: + # print("Error!") + # print(e) + # # raise + except e: + print("Error: ", e) + print(citable_item) -- GitLab