-
Notifications
You must be signed in to change notification settings - Fork 0
/
google_sheets_api.py
37 lines (29 loc) · 988 Bytes
/
google_sheets_api.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
import gspread
from oauth2client.service_account import ServiceAccountCredentials
scopes = [
'https://www.googleapis.com/auth/spreadsheets',
'https://www.googleapis.com/auth/drive'
]
creds = ServiceAccountCredentials.from_json_keyfile_name(
"./configs/gsheets.json", scopes=scopes)
file = gspread.authorize(creds)
workbook = file.open("ANPR")
sheet = workbook.sheet1
def append_data(plate, date, time, state):
sheet.append_row([plate, date, time, state])
def fetch_data():
return sheet.get_all_records()
def execute_query(query_plate):
query_plate_cpy = query_plate.replace(" ", "")
message = ""
result = {}
flag = 0
for record in sheet.get_all_records():
if record['Registration_Number'].replace(" ", "") == query_plate_cpy:
flag = 1
message = "Success"
result = record
break
if flag == 0:
message = "Fail"
return message, result