123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- #!/usr/bin/python
- # 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/>.
- import sys
- import urllib
- import urllib2
- import json
- import random
- import re
- accesskey = "XXXXXXXX"
- jsonreq = "http://isbndb.com/api/v2/json/" + accesskey + "/books/?i=combined&q="
- qstring = ""
- for arg in sys.argv:
- qstring = qstring + " " + arg
- query = urllib.quote_plus(qstring)
- queryURL = jsonreq + query
- jsondata = urllib2.urlopen(queryURL).read()
- data = json.loads(jsondata)
- for book in data['data']:
- if book['author_data']:
- authorid = book['author_data'][0]['id']
- authorlast = re.split('_', authorid)
- rand = random.randint(0, 3000)
- bibtexkey = authorlast[0] + str(rand)
- 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)
|