""" | |
Create .env File and Test Supabase Connection | |
This script creates a .env file with hardcoded values and then tests the connection to Supabase. | |
""" | |
import os | |
import sys | |
import time | |
def create_env_file(api_key): | |
""" | |
Create a .env file with the provided API key. | |
Args: | |
api_key: The Supabase API key | |
""" | |
env_content = f""" | |
# Supabase Configuration | |
SUPABASE_URL=https://tjamxhvvtnypbadvrkjq.supabase.co | |
SUPABASE_KEY={api_key} | |
""" | |
with open(".env", "w") as f: | |
f.write(env_content) | |
def test_supabase(): | |
"""Test the connection to Supabase.""" | |
try: | |
from supabase import create_client | |
from dotenv import load_dotenv | |
load_dotenv(override=True) | |
# Get Supabase URL and key | |
supabase_url = os.getenv("SUPABASE_URL") | |
supabase_key = os.getenv("SUPABASE_KEY") | |
if supabase_key: | |
masked_key = supabase_key[:4] + "*" * (len(supabase_key) - 8) + supabase_key[-4:] if len(supabase_key) > 8 else "****" | |
else: | |
return False | |
client = create_client(supabase_url, supabase_key) | |
result = client.table("test_connection").select("*").limit(1).execute() | |
return True | |
except Exception as e: | |
import traceback | |
traceback.print_exc() | |
return False | |
def main(): | |
"""Main function.""" | |
api_key = input("> ").strip() | |
if not api_key: | |
return | |
create_env_file(api_key) | |
time.sleep(1) | |
# Test Supabase connection | |
success = test_supabase() | |
if success: | |
else: | |
if __name__ == "__main__": | |
main() |