This is (not) specifically related to chemistry or open source, but I don't know where to look.
I have a number of articles (a couple of hunderd) in a bibtex file, and some of them are missing their DOI, which is very useful for getting hyperlinked references in PDF files.
Is there a way to get the DOI fields for all of them automatically?
Obviously, I can parse the bibtex file on my own with some script and serve any kind of information about the article (authors, title, journal, etc.).
Solution in Python
Here is a function in Python based on the code Rich posted in Ruby, which queries crossref and return a list of matching DOIs...
import urllib
import xml.dom.minidom
def getdoi(account, journal=False, volume=False, issue=False, spage=False, date=False):
journal = journal.replace(" ", "%20")
url = "http://www.crossref.org/openurl?pid=account"
if journal:
url += "&title=%s" %journal
if volume:
url += "&volume=%i" %int(volume)
if issue:
url += "&issue=%i" %int(issue)
if spage:
url += "&spage=%i" %int(spage)
if date:
url += "&date=%si" %date
url += "&redirect=false&format=unixref"
txt = urllib.urlopen(url).read()
doc = xml.dom.minidom.parseString(txt)
dois = doc.getElementsByTagName('doi')
dois = [doi.childNodes[0].nodeValue for doi in dois]
return dois