123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- import sys
- import urllib
- import json
- import random
- import re
- accesskey = "W9V9X9VN"
- 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 = urllib.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)
|