-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes issue #1, a break in biorxiv id's that are given directly. Fixe…
…s some instabilities caused by stray whitespace or leading slashes. Reformatted code to be closer to PEP8. Updated tests to use Pytest. Fixed requirements.txt, which was missing the ``requests`` package.
- Loading branch information
scnerd
committed
Jul 14, 2020
1 parent
545a63f
commit 4252cb8
Showing
6 changed files
with
185 additions
and
136 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -102,3 +102,6 @@ venv.bak/ | |
|
||
# mypy | ||
.mypy_cache/ | ||
|
||
# Pycharm | ||
.idea |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,35 @@ | ||
from refid2bib.core import get_biorxiv_bibtex, get_doi_bibtex, get_arxiv_bibtex, get_pmid_bibtex | ||
import re | ||
|
||
from refid2bib.core import get_biorxiv_bibtex, get_doi_bibtex, get_arxiv_bibtex, get_pmid_bibtex | ||
|
||
bibtex_functions = { | ||
'biorxiv':get_biorxiv_bibtex, | ||
'doi':get_doi_bibtex, | ||
'arxiv':get_arxiv_bibtex, | ||
'pmid':get_pmid_bibtex} | ||
'biorxiv': get_biorxiv_bibtex, | ||
'doi': get_doi_bibtex, | ||
'arxiv': get_arxiv_bibtex, | ||
'pmid': get_pmid_bibtex | ||
} | ||
|
||
def refid2bib(ref, short_name=None, lastname_first=True, ref_type=None): | ||
|
||
tests = {'doi':'^doi: ?|^https?://doi.org/|^https?://dx.doi.org/', | ||
'biorxiv':'^biorxiv ?|^biorxiv:', | ||
'arxiv': '^arxiv:|^https?://arxiv.org/abs/', | ||
'pmid': '^pmid: ?|^(?=pmc\d*)', | ||
def refid2bib(ref, short_name=None, lastname_first=True, ref_type=None): | ||
tests = { | ||
'doi': r'^doi: ?|^https?://doi.org/|^https?://dx.doi.org/', | ||
'biorxiv': r'^biorxiv:|^biorxiv ?', | ||
'arxiv': r'^arxiv:|^https?://arxiv.org/abs/', | ||
'pmid': r'^pmid: ?|^(?=pmc\d*)', | ||
} | ||
|
||
if ref_type in tests.keys(): | ||
query = re.search( tests[ref_type], ref.lower() ) | ||
query = re.search(tests[ref_type], ref.lower()) | ||
oid = ref[query.span()[1]:] | ||
else: | ||
for c, q in tests.items(): | ||
query = re.search( q, ref.lower() ) | ||
query = re.search(q, ref.lower()) | ||
if query is not None: | ||
oid = ref[query.span()[1]:] | ||
ref_type = c | ||
break | ||
else: | ||
raise ValueError( 'Cannot assign reference type for {}'.format(ref) ) | ||
else: | ||
raise ValueError('Cannot assign reference type for {}'.format(ref)) | ||
|
||
oid = oid.lstrip('/').strip() | ||
return bibtex_functions[ref_type](oid, short_name=short_name, lastname_first=lastname_first) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,10 @@ | ||
import sys | ||
from refid2bib import refid2bib | ||
|
||
oid = sys.argv[1] | ||
print( '\n') | ||
print( refid2bib(oid) ) | ||
|
||
if __name__ == '__main__': | ||
import argparse | ||
parser = argparse.ArgumentParser() | ||
parser.add_argument('document_id', help='DOI, ArXiv ID, etc. of the document you wish to look up') | ||
args = parser.parse_args() | ||
|
||
print(refid2bib(args.document_id)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
feedparser | ||
nameparser | ||
nameparser | ||
requests |
Oops, something went wrong.