Spaces:
Sleeping
Sleeping
| from pydantic import BaseModel | |
| from dotenv import load_dotenv | |
| from supabase import create_client | |
| from functools import lru_cache | |
| import os | |
| load_dotenv() | |
| class Supabase_Settings(BaseModel): | |
| SUPABASE_URL: str = os.getenv("SUPABASE_URL") | |
| SUPABASE_ANON_KEY: str = os.getenv("SUPABASE_ANON_KEY") | |
| class Supabase_Clients: | |
| values = Supabase_Settings() | |
| anon_supabase = create_client(values.SUPABASE_URL, values.SUPABASE_ANON_KEY) | |
| def fetch_data(user_id:str): | |
| supabase_clients=Supabase_Clients() | |
| supabase = supabase_clients.anon_supabase | |
| response_0 = ( | |
| supabase.table("receipt_radar_structured_data") | |
| .select("location") | |
| .eq("user_id",f"{user_id}") | |
| .eq("brand_category","Travel and Leisure") | |
| .execute() | |
| ) | |
| print("Printing fetched data") | |
| print(response_0) | |
| return response_0.data | |
| def authenticate_user(apitoken: str): | |
| supabase_clients = Supabase_Clients() | |
| supabase = supabase_clients.anon_supabase | |
| try: | |
| user = supabase.auth.get_user(apitoken) | |
| return str(user.user.id) | |
| except Exception as e: | |
| print("Exceptional error") | |
| return "Exceptional error" | |
| def fetch_cards_data(user_id:str): | |
| supabase_clients=Supabase_Clients() | |
| supabase = supabase_clients.anon_supabase | |
| response_0 = ( | |
| supabase.table("receipt_radar_structured_data") | |
| .select("brand") | |
| .eq("user_id",f"{user_id}") | |
| .execute() | |
| ).data | |
| response_1 = ( | |
| supabase.table("card_market") | |
| .select("brand_name") | |
| .execute() | |
| ).data | |
| brands_response_1_set = set(item['brand_name'].lower() for item in response_1) | |
| common_brands = [item['brand'] for item in response_0 if item['brand'].lower() in brands_response_1_set] | |
| print("common_brands") | |
| print(common_brands) | |
| return common_brands |