Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ChemRxiv publications #170

Merged
merged 5 commits into from Jan 24, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
35 changes: 35 additions & 0 deletions wikidataintegrator/wdi_helpers/publication.py
Expand Up @@ -39,6 +39,7 @@ class Publication:
'europepmc': 'Q5412157',
'arxiv': 'Q118398',
'biorxiv': 'Q19835482',
'chemrxiv': 'Q50012382',
}

def __init__(self, title=None, instance_of=None, subtitle=None, authors=None,
Expand Down Expand Up @@ -209,6 +210,8 @@ def make_reference(self):
edt_id_id, ext_id_prop = self.ids['arxiv'], PROPS['arxiv id']
elif self.source == 'biorxiv':
edt_id_id, ext_id_prop = self.ids['biorxiv'], self.ID_TYPES['biorxiv']
elif self.source == 'chemrxiv':
edt_id_id, ext_id_prop = self.ids['doi'], self.ID_TYPES['doi']
else:
raise ValueError(f'Unhandled source: {self.source}')

Expand Down Expand Up @@ -548,12 +551,44 @@ def biorxiv_api_to_publication(biorxiv_id: str, id_type='biorxiv') -> Publicatio
return publication


def chemrxiv_api_to_publication(chemrxiv_id: str, id_type='chemrxiv') -> Publication:
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In theory, this could be used for other figshare *Rxiv servers as well, but the JSON response doesn't give any hints as to which database the result is actually part of

"""Make a :class:`Publication` from a ChemRxiv identifier."""
url = f'https://api.figshare.com/v2/articles/{chemrxiv_id}'
headers = {
'User-Agent': config['USER_AGENT_DEFAULT']
}
res = requests.get(url, headers=headers)
res.raise_for_status()
res_json = res.json()

publication = Publication(
title=res_json['title'],
ref_url=res_json['figshare_url'],
authors=[
{
'full_name': author['full_name'],
'orcid': author.get('orcid_id'),
}
for author in res_json['authors']
],
publication_date=datetime.datetime.strptime(res_json['published_date'], '%Y-%m-%dT%H:%M:%SZ'),
ids={
'doi': res_json['doi'],
},
source='chemrxiv',
)
publication.instance_of = 'preprint'
publication.published_in_qid = Publication.SOURCES['chemrxiv']
return publication


class PublicationHelper:
SOURCE_FUNCT = {
'crossref': crossref_api_to_publication,
'europepmc': europepmc_api_to_publication,
'arxiv': arxiv_api_to_publication,
'biorxiv': biorxiv_api_to_publication,
'chemrxiv': chemrxiv_api_to_publication,
}

def __init__(self, ext_id, id_type, source):
Expand Down