-
-
Save emanuelduss/547f1f7b358717d09c7b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python | |
| import json, sys | |
| from urllib.request import urlopen | |
| API='http://xisbn.worldcat.org/webservices/xid/isbn/{isbn}?method=getMetadata&format=json&fl=*' | |
| OPT_KEYS = ['author', 'city', 'ed', 'form', 'lang', 'lccn', | |
| 'originalLang', 'publisher', 'year'] | |
| def get_metadata(isbn): | |
| rawjson = urlopen(API.format(isbn=isbn)).readall().decode('utf-8') | |
| response = json.loads(rawjson) | |
| if not response['stat'] == 'ok': | |
| sys.exit("could not get data from xISBN") | |
| data = response['list'][0] | |
| # fill optional keys | |
| for k in OPT_KEYS: | |
| if k not in data: data[k] = "" | |
| # make lccn list | |
| data['lccn'] = ', '.join(data['lccn']) | |
| # unpack isbn, form, oclcnum | |
| data['isbn'] = data['isbn'][0] | |
| data['form'] = data['form'][0] | |
| data['oclcnum'] = data['oclcnum'][0] | |
| return data | |
| # main | |
| if len(sys.argv) < 1: | |
| sys.exit("usage: {} ISBN [--url]".format(sys.argv[0])) | |
| data = get_metadata(sys.argv[1].replace("-","")) | |
| print("""Create Wiki Site: http://wiki.luxeria.ch/biblio:{isbn}?do=edit | |
| ===== {title} ===== | |
| <block right> | |
| {{{{http://covers.openlibrary.org/b/isbn/{isbn}-M.jpg}}}} | |
| </block> | |
| ---- dataentry book ---- | |
| type: book | |
| isbn13: {isbn} | |
| author: {author} | |
| publisher: {publisher} | |
| year: {year} | |
| lang: {lang} | |
| origlang: {originalLang} | |
| worldcat_oclc: {oclcnum} | |
| city: {city} | |
| edition: {ed} | |
| form_onix: {form} | |
| lccns: {lccn} | |
| donor_user: | |
| reader_user: | |
| borrower_user: | |
| borrowdate_dt: | |
| ----""".format(**data)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment