Skip to content

Instantly share code, notes, and snippets.

@dartar
Last active November 5, 2015 00:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dartar/397ddb8c46b517b14c22 to your computer and use it in GitHub Desktop.
Save dartar/397ddb8c46b517b14c22 to your computer and use it in GitHub Desktop.
#!/usr/bin/python
import httplib
import sys
base_url = "dx.doi.org"
for line in sys.stdin:
doi = line.strip()
url = base_url + doi
conn = httplib.HTTPConnection(base_url)
conn.request("HEAD", "/" + doi)
res = conn.getresponse()
e = 1 if res.status == 303 else 0
print doi + "\t" + str(e)
@dartar
Copy link
Author

dartar commented Nov 5, 2015

for caching metadata instead of calling the resolver, we can use the works endpoint of the API, something like:

base_url = "http://api.crossref.org/works/"
for line in sys.stdin:
    url = base_url + doi
    try:
        request = urllib.request.Request(url)
        response = urllib.request.urlopen(request)
        r = response.read().decode('utf-8')
        response.close()
        j = json.loads(r)
        dlist[doi] =j['message']
    except:
        dlist[doi] = None

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment