-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathclassBook.py
More file actions
110 lines (93 loc) · 3.23 KB
/
Copy pathclassBook.py
File metadata and controls
110 lines (93 loc) · 3.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# Rowan Sharman
import isbnlib
import textMiner
class Book:
'''
A class to keep track of all information known about a book.
Also contains functions which call textMiner to get more information.
ATTRIBUTES:
isbn
title
author
publisher
year
language
authorLoc
publisherLoc
plotLoc
'''
def __init__(self, info):
'''
Instantiate Book objects with either ISBN or title
INPUT: String that is either a book title or an ISBN
OUTPUT: None
'''
if isbnlib.notisbn(info): # Instantiate using ISBN
self.title = info
self.isbn = ''
else: # Instantiate using title
self.isbn = info
self.title = ''
# Create all attributes that will be used
self.author = ''
self.publisher = ''
self.year = ''
self.language = ''
self.authorLoc = ''
self.publisherLoc = ''
self.plotLoc = ''
def getInfo(self):
'''
Get basic info stored in remote ISBN database
INPUT: None
OUTPUT: None (updates attributes of self)
'''
self.info = isbnlib.meta(self.isbn)
# If ISBN found in database, write info to attributes
if self.info is not None:
self.title = self.info['Title']
self.author = self.info['Authors']
self.publisher = self.info['Publisher']
self.year = self.info['Year']
self.language = self.info['Language']
def getLocations(self):
'''
Use textMiner to get whatever locations possible
INPUT: None
OUTPUT: None (updates attributes of self)
'''
if self.title != '':
self.authorLoc = textMiner.getAuthorLocation(self)
self.plotLoc = textMiner.getPlotLocation(self)
else:
self.authorLoc = 'Book is missing title'
if self.publisher != '':
self.publisherLoc = textMiner.getPublisherLocation(self)
else:
self.publisherLoc = 'Book is missing publisher info'
def __str__(self): # Print all known information about the book
'''
Provide pretty printable string containing all known attributes
INPUT: None
OUTPUT: Printable string
'''
infoString = ''
infoString += ('Title:\t\t\t' + self.title + '\n')
# Deal with printing single/multiple authors coherently
plural = 'Author:\t\t\t'
authors = ''
if self.author != '':
for element in self.author:
if len(authors) > 1:
plural = 'Authors:\t\t'
authors += ', ' + element
else:
authors += element
infoString += (plural + authors + '\n')
infoString += ('Publisher:\t\t' + self.publisher + '\n')
infoString += ('Year:\t\t\t' + self.year + '\n')
infoString += ('Language:\t\t' + self.language + '\n')
infoString += ('Author Location:\t' + self.authorLoc + '\n')
infoString += ('Publisher Location:\t' + self.publisherLoc + '\n')
infoString += ('Plot Location:\t\t' + self.plotLoc + '\n')
return infoString