Spaces:
Paused
Paused
Download db.py from iatechaways/mail_bot: direct link, hf CLI and curl.
- Browser
- Download file 910 Bytes
-
https://huggingface.co/spaces/iatechaways/mail_bot/resolve/main/db.py
- Command line
-
hf download hf://spaces/iatechaways/mail_bot/db.py
-
curl -L -o db.py https://huggingface.co/spaces/iatechaways/mail_bot/resolve/main/db.py
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 | |