doi2bib2 icon indicating copy to clipboard operation
doi2bib2 copied to clipboard

Programmatic Access to Website?

Open YogiOnBioinformatics opened this issue 1 year ago • 9 comments

I love the website you have set up! 🙂

Is there any way to programatically input a DOI and get the info back from your website to be able to parse?

YogiOnBioinformatics avatar Mar 27 '23 02:03 YogiOnBioinformatics

@davidagraf sorry to bother but wanted to follow up on this.

YogiOnBioinformatics avatar Jul 01 '23 16:07 YogiOnBioinformatics

I am also interested on this. Does anyone know a curl command that can do the job?

adosar avatar Nov 26 '23 20:11 adosar

@davidagraf any response yet?

YogiOnBioinformatics avatar Dec 05 '23 01:12 YogiOnBioinformatics

Unfortunately, we had to block programmatic access due to quota/budget limitations.

thurnherr avatar Dec 05 '23 06:12 thurnherr

@YogiOnBioinformatics @adosar

Sorry if I am late to this, but you can achieve this using curl. Suppose you want to fetch the BibTeX entry for this paper, you just run the following:

$ curl -LH "Accept: application/x-bibtex" https://doi.org/10.1056/NEJMoa2001017

and you get

@article{Zhu_2020, title={A Novel Coronavirus from Patients with Pneumonia in China, 2019}, volume={382}, ISSN={1533-4406}, url={http://dx.doi.org/10.1056/NEJMoa2001017}, DOI={10.1056/nejmoa2001017}, number={8}, journal={New England Journal of Medicine}, publisher={Massachusetts Medical Society}, author={Zhu, Na and Zhang, Dingyu and Wang, Wenling and Li, Xingwang and Yang, Bo and Song, Jingdong and Zhao, Xiang and Huang, Baoying and Shi, Weifeng and Lu, Roujian and Niu, Peihua and Zhan, Faxian and Ma, Xuejun and Wang, Dayan and Xu, Wenbo and Wu, Guizhen and Gao, George F. and Tan, Wenjie}, year={2020}, month=feb, pages={727–733} }

You can read more about DOI Content Negotiation here.

kakumarabhishek avatar May 22 '24 09:05 kakumarabhishek

@kakumarabhishek this is brilliant!

Thanks so much!

YogiOnBioinformatics avatar May 22 '24 16:05 YogiOnBioinformatics

@YogiOnBioinformatics @adosar

Sorry if I am late to this, but you can achieve this using curl. Suppose you want to fetch the BibTeX entry for this paper, you just run the following:

$ curl -LH "Accept: application/x-bibtex" https://doi.org/10.1056/NEJMoa2001017

and you get

@article{Zhu_2020, title={A Novel Coronavirus from Patients with Pneumonia in China, 2019}, volume={382}, ISSN={1533-4406}, url={http://dx.doi.org/10.1056/NEJMoa2001017}, DOI={10.1056/nejmoa2001017}, number={8}, journal={New England Journal of Medicine}, publisher={Massachusetts Medical Society}, author={Zhu, Na and Zhang, Dingyu and Wang, Wenling and Li, Xingwang and Yang, Bo and Song, Jingdong and Zhao, Xiang and Huang, Baoying and Shi, Weifeng and Lu, Roujian and Niu, Peihua and Zhan, Faxian and Ma, Xuejun and Wang, Dayan and Xu, Wenbo and Wu, Guizhen and Gao, George F. and Tan, Wenjie}, year={2020}, month=feb, pages={727–733} }

You can read more about DOI Content Negotiation here.

Is it possible to pretty print this? Maybe it is related to this?

adosar avatar May 23 '24 22:05 adosar

@adosar I may be too late to answer, but I managed to get away with a (GNU) sed one-liner, which you may find helpful.

Building on the example curl command above:

curl --silent -LH "Accept: application/x-bibtex" 'https://doi.org/10.1056/NEJMoa2001017' | sed -E -e 's/}$/\n}/g' -e 's/^\s//g' -e 's/,\s([a-zA-Z]+=)/,\n    \1/g'

Which results in the following output:

@article{Zhu_2020,
    title={A Novel Coronavirus from Patients with Pneumonia in China, 2019},
    volume={382}, ISSN={1533-4406},
    url={http://dx.doi.org/10.1056/NEJMoa2001017},
    DOI={10.1056/nejmoa2001017},
    number={8},
    journal={New England Journal of Medicine},
    publisher={Massachusetts Medical Society},
    author={Zhu, Na and Zhang, Dingyu and Wang, Wenling and Li, Xingwang and Yang, Bo and Song, Jingdong and Zhao, Xiang and Huang, Baoying and Shi, Weifeng and Lu, Roujian and Niu, Peihua and Zhan, Faxian and Ma, Xuejun and Wang, Dayan and Xu, Wenbo and Wu, Guizhen and Gao, George F. and Tan, Wenjie},
    year={2020},
    month=feb,
    pages={727–733} 
}

fbucchini avatar Sep 02 '24 18:09 fbucchini

@fbucchini Perfect! I just can't understand why the output formatting changed. Previously there was need to further process the returned string.

adosar avatar Sep 02 '24 23:09 adosar