def get_tr_metadata(ev_tr_dict): cord_by_doi, cord_by_pmid = get_cord_info() # If has DOI, look up in CORD19 title, authors, journal, date = (None, None, None, None) if ev_tr_dict.get('DOI'): doi = ev_tr_dict['DOI'] cord_entry = cord_by_doi.get(doi) if cord_entry: return (cord_entry['title'], cord_entry['authors'], cord_entry['journal'], cord_entry['publish_time'].year) # Article not in CORD-19 corpus, get metadata from Crossref print("Querying crossref") cr_entry = crossref_client.get_metadata(doi) if cr_entry: try: author_str = '; '.join([ f"{auth['family']}, {auth.get('given', '')}" for auth in cr_entry['author'] ]) except KeyError: try: author_str = '; '.join( [f"{auth['name']}" for auth in cr_entry['author']]) except KeyError: author_str = '' title_list = cr_entry['title'] if title_list: title = title_list[0] container_list = cr_entry['container-title'] if container_list: journal = container_list[0] return (title, author_str, journal, cr_entry['issued']['date-parts'][0][0]) # If we got here, then we haven't found the metadata yet, try by PMID if ev_tr_dict.get('PMID'): pmid = ev_tr_dict['PMID'] cord_entry = cord_by_pmid.get(pmid) if cord_entry: return (cord_entry['title'], cord_entry['authors'], cord_entry['journal'], cord_entry['publish_time'].year) print("Querying Pubmed") pm_entry = pubmed_client.get_metadata_for_ids([pmid]) if pm_entry: pm_md = pm_entry[pmid] author_str = '; '.join(pm_md['authors']) return (pm_md['title'], author_str, pm_md.get('journal_title', ''), pm_md['publication_date']['year']) # No luck, return empty strings return ('', '', '', '')
def _get_doi_title(doi): m = crossref_client.get_metadata(doi) if m: title = m.get('title') if title: return title[0]
def test_get_metadata(): metadata = crossref_client.get_metadata(test_doi) assert (metadata['DOI'] == test_doi) assert unicode_strs(metadata) metadata = crossref_client.get_metadata('xyz') assert (metadata is None)
def test_get_metadata(): metadata = crossref_client.get_metadata(test_doi) assert metadata['DOI'] == test_doi assert unicode_strs(metadata) metadata = crossref_client.get_metadata('xyz') assert metadata is None