Created
November 17, 2017 18:41
-
-
Save dleehr/006ddf61f982e56922c5642edf57a1a9 to your computer and use it in GitHub Desktop.
crossref CN lookups
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
#!/bin/bash | |
curl -SLH "Accept: text/bibliography; style=apa" http://dx.doi.org/$1 |
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
#!/usr/bin/env python | |
from __future__ import print_function | |
from habanero import cn | |
import sys | |
doi_name = 'doi:' + sys.argv[1] | |
print(cn.content_negotiation(ids=doi_name, format="text", style="apa")) |
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
#!/usr/bin/env python | |
from __future__ import print_function | |
import requests | |
import sys | |
headers = {'Accept': 'text/bibliography; style=apa', 'Accept-Encoding': 'utf-8'} | |
response = requests.get('http://dx.doi.org/' + sys.argv[1], headers=headers) | |
print(response.text.encode(response.encoding).decode('utf-8')) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Using habanero to do content negotiation can result in mangled character encoding.
For example, looking up doi:10.1093/bioinformatics/btp324 results in different output from
habanero.cn
vs a standardcurl
:lookup_curl.sh:
lookup_habanero.py:
Requests marks the response encoding as
ISO-8859-1
. Whilecn
returns the response text, it does not pass along the encoding.