Simple, an ISBN/Author-Title to BibTeX entry generator.
Have you been doing research, and forgot to write down a citation, or forgot to enter it into your citation management system? Exactly! Well, that is what ths is for, just write down the author and name of the book, and it outputs BibTeX to import into about any reference manager.
Simple, you need an install of python, I just use the standard Library. You also need a ISBNDB.com API Key, which you can get here: ISBNDB.Com Key manager.
You can resolve the noweb labels yourself and do copy/paste, but that's the hard way! The easy way is to open it in emacs, by typing C-x C-f /path/to/file RET, then type C-c C-v t. This will tangle the file to the current directory as isbn2bibtex.py.
It's simple to use, just type "isbn2bibtex.py 'author title'" in a terminal session. So if we ran "isbn2bibtex.py 'siert'" we get:
@Book{kara75, author = "{Kara Grace ManJian Siert}", title = "{Tales of Cunburra and Other Stories}", publisher = "{Swirl}" }
Copyright FlintFam Systems Management, 2013. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.
Well, we need a few libraries for this to work.
import sys import urllib import urllib2 import json import random import re
to access the argument array.
to encode the arguments for the query.
to perform the query.
to parse the results of the query to a python data structure.
to create a random number for the key generation.
to obtain the author's last name for the key generation.
We have a few variables to create:
accesskey = "XXXXXXXX" jsonreq = "http://isbndb.com/api/v2/json/" + accesskey + "/books/?i=combined&q="
Well, here's the thing, this body needs a few things, but we have a single entry for simplicity.
<<ConstructURL>> <<QueryAndParse>> for book in data['data']: if book['author_data']: <<KeyCreation>> <<BibTeXOutput>>
First, we need to construct the query URL.
qstring = "" for arg in sys.argv: qstring = qstring + " " + arg query = urllib.quote_plus(qstring) queryURL = jsonreq + query
We also have to actually query the server, this is simple, especially since we want our data.
jsondata = urllib2.urlopen(queryURL).read() data = json.loads(jsondata)
Okay, every BibTeX entry must have a key, right? well, we have to create a key, and this is how we do it.
authorid = book['author_data'][0]['id'] authorlast = re.split('_', authorid) rand = random.randint(0, 3000) bibtexkey = authorlast[0] + str(rand)
We now have to create the entry, and output it.
authoritem = "" first = 1 for author in book['author_data']: authorname = author['name'] if first == 0: authoritem = authoritem + " and " + authorname else: authoritem = authorname first = 0 titleitem = book['title_latin'] publisher = book['publisher_name'] entry = "@Book{" + bibtexkey + ",\nauthor = \"{" + authoritem + "}\",\ntitle = \"{" + titleitem + "}\",\npublisher = \"{" + publisher + "}\"\n}\n\n" print(entry)
# <<CopyrightStatement>> <<Imports>> <<MiscVars>> <<Body>>