mail_bot / db.py
iatechaways's picture
Refactor email handling and model inference.
f814c93
Raw History Blame Contribute Delete
910 Bytes
# db.py
import os
import psycopg2
import psycopg2.extras
import urllib.parse as urlparse
DATABASE_URL = os.getenv("DATABASE_URL") # full connection string
def fetch_client_info(identifier: str):
"""Return a dict row from insurance_clients by client_id or policy_number."""
if not identifier:
return None
try:
conn = psycopg2.connect(DATABASE_URL, cursor_factory=psycopg2.extras.RealDictCursor)
cur = conn.cursor()
cur.execute("""
SELECT * FROM insurance_clients
WHERE client_id = %s OR policy_number = %s
LIMIT 1;
""", (identifier, identifier))
row = cur.fetchone()
cur.close()
conn.close()
if row:
return dict(row)
return None
except Exception as e:
# keep simple logging - the Space logs will show this
print("DB error:", e)
return None