-
Notifications
You must be signed in to change notification settings - Fork 169
Expand file tree
/
Copy pathbook_review.py
More file actions
29 lines (23 loc) · 958 Bytes
/
Copy pathbook_review.py
File metadata and controls
29 lines (23 loc) · 958 Bytes
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
import os
from pyairtable import Api
class BookReview:
def __init__(self):
self.api = Api(os.environ['AIRTABLE_API_KEY'])
self.table = self.api.table('appWM08dyTvVAHd5e', 'tbl67ZaTNCeuPLGfI')
def get_book_ratings(self, sort="ASC", max_records=10):
if not sort:
return self.table.all(max_records=max_records)
elif sort == "ASC":
rating = ["Rating"]
elif sort == "DESC":
rating = ["-Rating"]
table = self.table.all(sort=rating, max_records=max_records)
return table
def add_book_rating(self, book_title, book_rating, notes=None):
fields = {'Book': book_title, 'Rating': book_rating, 'Notes': notes}
self.table.create(fields=fields)
if __name__ == '__main__':
br = BookReview()
# br.add_book_rating('Infinite Jest', 7.0)
get_book_ratings = br.get_book_ratings(sort="DESC", max_records=1)
print(get_book_ratings)