Commit 38dd95cc authored by Rajasingam kokilan's avatar Rajasingam kokilan

raspberryPi.py

parent 3bc0126e
from __future__ import print_function
import operator
import gspread
from google.oauth2.service_account import Credentials
def create_assertion_session_service_account(url):
scopes = [
'https://www.googleapis.com/auth/spreadsheets',
'https://www.googleapis.com/auth/drive'
]
credentials = Credentials.from_service_account_file(
'credentials.auth.json',
scopes=scopes
)
gc = gspread.authorize(credentials)
sh = gc.open_by_url(url)
worksheet = sh.sheet1
return worksheet
def dataIndexIdentification(url):
worksheet = create_assertion_session_service_account(url)
col_list = worksheet.row_values(1)
jsonConfig = {}
d1 = []
for i, data1 in enumerate(col_list, start=0):
commonColObject = {}
commonColObject["index"] = i
jsonConfig[col_list[i]] = commonColObject
return jsonConfig
def classifier(water_level, url):
search_keys = dataIndexIdentification(url)
worksheet = create_assertion_session_service_account(url)
count_array = []
count_dict = {}
search_keys_array = []
search_keys_dict = {}
for key, value in search_keys.items():
search_keys_dict[key] = worksheet.col_values(value['index'] + 1)[1:]
count_dict[key + "_count"] = 0
count_array.append(count_dict)
search_keys_array.append(search_keys_dict)
water_levels = water_level
for water_level in water_levels:
for search_key in search_keys_array:
for key, value in search_key.items():
if water_levels in value:
for k, v in count_array[0].items():
if k == key + "_count":
count_array[0][key + "_count"] = count_array[0][key + "_count"] + 1
sorted_x = sorted(count_array[0].items(), key=operator.itemgetter(1))
if sorted_x[-1][1] == 0:
print("income water persentage")
else:
print("number of door need oppen " + sorted_x[-1][0][:-6] + " stay safe")
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment