1
2
3 """
4 Retreive bibliographic information for a given ISBN.
5
6 """
7
8
9
10
11 __docformat__ = 'restructuredtext en'
12
13
14
15
16 import sys
17 from os import path
18 from optparse import OptionParser
19 from exceptions import BaseException
20
21 from config import *
22 from common import *
23
24
25
26
27 PRINT_FIELDS = [
28 'title',
29 'authors',
30 'publisher',
31 'year',
32 'lang',
33 ]
34
35 _DEV_MODE = False
36
37
38
40
41 usage = '%prog [options] ISBNs ...'
42 version = "version %s" % script_version
43 epilog=''
44 description = 'Return bibliographic information from webservices for ' \
45 'supplied ISBNs.'
46 optparser = OptionParser (usage=usage, version=version,
47 description=description, epilog=epilog)
48 add_shared_options (optparser)
49
50
51 options, isbns = optparser.parse_args()
52
53 if (not isbns):
54 optparser.error ('No ISBNs specified')
55 check_shared_options (options, optparser)
56
57
58 return isbns, options
59
60
62 isbn_list, options = parse_args()
63 webqry = construct_webquery (options.webservice, options.service_key)
64 try:
65 for isbn in isbn_list:
66 print '%s:' % isbn
67 rec_list = webqry.query_bibdata_by_isbn (isbn, format='bibrecord')
68 if (rec_list):
69 for f in PRINT_FIELDS:
70 if (getattr (rec_list[0], f)):
71 print ' %s: %s' % (f, getattr (rec_list[0], f))
72 else:
73 print ' No results'
74 except BaseException, err:
75 if (_DEV_MODE or options.debug):
76 raise
77 else:
78 sys.exit (err)
79 except:
80 if (_DEV_MODE or option.debug):
81 raise
82 else:
83 sys.exit ("An unknown error occurred.")
84
85
86
87
88
89
90 if __name__ == '__main__':
91 main()
92
93
94
95