Last active
February 7, 2023 22:29
-
-
Save sarpavci/0cc88ecea56e8d5344a7515400287371 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import json | |
| import os | |
| from supabase import create_client, Client | |
| # https://github.com/supabase-community/supabase-py | |
| url: str = 'https://xzdacscxdkwhvzcnexwt.supabase.co' # os.environ.get("SUPABASE_URL") | |
| key: str = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6Inh6ZGFjc2N4ZGt3aHZ6Y25leHd0Iiwicm9sZSI6InNlcnZpY2Vfcm9sZSIsImlhdCI6MTY3NTgwNjIwNywiZXhwIjoxOTkxMzgyMjA3fQ.OicX8vKHCvO0eQwXsWi2TkXpM0fjW3glJ461NiBeygg' # os.environ.get("SUPABASE_KEY") | |
| supabase: Client = create_client(url, key) | |
| # Initialize app | |
| slots_data = supabase.from('slots').select("*") | |
| def handle_keypress(x, y): | |
| slot_item = { | |
| slot_number: len(slots_data) + 1, | |
| pos_x: x, | |
| pos_y: y, | |
| state: 'empty', | |
| is_active: True, | |
| } | |
| data = supabase.table('slots').insert(slot_item).execute() | |
| if len(data.data) > 0: | |
| slots_data.append(slot_item) | |
| def on_frame_captured(cam_x, cam_y, load_data): | |
| for slot in slots_data: | |
| if (cam_x > slot["pos_x"] and cam_x < slot["pos_x"] + box_width) and | |
| (cam_y > slot["pos_y"] and cam_y < slot["pos_y"] + box_height): | |
| handle_slot(state, slot) | |
| cv2.on_frame_captured(handler) | |
| def handle_slot(load_data, slot): | |
| captured_state = 'full' if load_data["amount"] > 600 else 'empty' | |
| if captured_state != slot.state: | |
| data = supabase.table("slots").update({ "state": captured_state }).eq("id", slot["id"]).execute() | |
| print(data) | |
| if len(data.data) > 0: | |
| slots_data[index]["state"] = captured_state |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment