-
Notifications
You must be signed in to change notification settings - Fork 0
/
books.py
67 lines (58 loc) · 2.54 KB
/
books.py
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
import json
class Book(object):
def __init__(self, isbn, isbn13, title, series_title, image_url, started_at,
read_at, date_added, date_updated, read_count, item_type, shelves=[], authors=[]):
self.isbn = book_data.get('isbn')
self.isbn13 = book_data.get('isbn13')
self.title = book_data.get('title_without_series')
self.series_title = book_data.get('title')
self.image_url = book_data.get('image_url')
self.started_at = item_data.get('started_at')
self.read_at = item_data.get('read_at')
self.date_added = item_data.get('date_added')
self.date_updated = item_data.get('date_updated')
self.read_count = item_data.get('read_count')
self.item_type = item_type
self.shelves = shelves
self.authors = authors
@staticmethod
def from_dict(source):
book = Book(source['isbn'], source['isbn13'], source['title'], source['series_title'],
source['image_url'], source['started_at'], source['read_at'], source['date_added'],
source['date_updated'], source['read_count'], source['item_type'], source['shelves'], source['authors'])
return book
def to_dict(self):
dest = {
'isbn': self.isbn,
'isbn13': self.isbn13,
'title': self.title,
'series_title': self.series_title,
'image_url': self.image_url,
'started_at': self.started_at,
'read_at': self.read_at,
'date_added': self.date_added,
'date_updated': self.date_updated,
'read_count': self.read_count,
'item_type': self.item_type,
'shelves': self.shelves,
'authors': self.authors
}
return dest
def __repr__(self):
return(
Book(\
isbn={self.isbn}, \
isbn13={self.isbn13}, \
title={self.title}, \
series_title={self.series_title}, \
image_url={self.image_url}, \
started_at={self.started_at}, \
read_at={self.read_at}, \
date_added={self.date_added}, \
date_updated={self.date_updated}, \
read_count={self.read_count}, \
item_type={self.item_type}, \
shelves={self.shelves}, \
authors={self.authors}\
)'
)