forked from KeithGalli/python-api-example
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbook_review_module2.py
More file actions
42 lines (32 loc) · 1.28 KB
/
book_review_module2.py
File metadata and controls
42 lines (32 loc) · 1.28 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
import os
from dotenv import load_dotenv
from pyairtable import Api
#this is from loading the .env file, which contains our AirTable API key.
load_dotenv()
env_path = '/Users/ottaaccount/Pyton_Class/python-api-example/.env'
load_dotenv(dotenv_path=env_path) # take environment variables from .env.
#section ends here for the dot env load
#testing_variable = os.getenv("TESTING_TOKEN") just to test out getting an environmental variable
#to get airtable api
#api_key = os.getenv("AIRTABLE_API_KEY")
#print(testing_variable)
#print(api_key)
api = Api(os.getenv("AIRTABLE_API_KEY"))
print(api)
#table = api.table('appExampleBaseId', 'tblExampleTableId') inside is the airtable base ID and table ID
#table = api.table('apptYkb7hxYFchrJA', 'tblYAreTaEsBGzRdG')
#print(table.all())
#to get certain section to like Rating only or Book title
#print(table.all()[0]['fields']['Rating'])
class BookReview:
def __init__(self):
self.api=Api(os.getenv("AIRTABLE_API_KEY"))
self.table = self.api.table('apptYkb7hxYFchrJA','tblYAreTaEsBGzRdG')
def get_book_ratings(self):
table = self.table.all()
return table
def add_book_ratings(self, book_title, book_rating, notes=None):
pass
if __name__ == "__main__":
br = BookReview()
print(br.get_book_ratings())