File size: 1,696 Bytes
c922f8b |
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 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
"""
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() |