Spaces:
Sleeping
Sleeping
File size: 3,792 Bytes
c024705 |
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 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
#!/usr/bin/env python3
"""
Test script to check database for user data
"""
import sqlite3
import json
def check_user_data():
"""Check if user data exists in the database"""
DB_FILE = "aimhsa.db"
try:
conn = sqlite3.connect(DB_FILE)
print("="*60)
print("DATABASE USER DATA CHECK")
print("="*60)
# Check if user exists
print("\n1. Checking if user 'Mugisha' exists:")
user = conn.execute("""
SELECT username, fullname, email, telephone, province, district, created_at
FROM users
WHERE username = ?
""", ('Mugisha',)).fetchone()
if user:
print("β
User found!")
print(f" Username: {user[0]}")
print(f" Full Name: {user[1]}")
print(f" Email: {user[2]}")
print(f" Phone: {user[3]}")
print(f" Province: {user[4]}")
print(f" District: {user[5]}")
print(f" Created At: {user[6]}")
else:
print("β User 'Mugisha' not found in users table")
# Check all users
print("\n2. All users in database:")
all_users = conn.execute("""
SELECT username, fullname, email, telephone, province, district
FROM users
ORDER BY created_at DESC
LIMIT 10
""").fetchall()
if all_users:
print(f"Found {len(all_users)} users:")
for u in all_users:
print(f" {u[0]} | {u[1]} | {u[2]} | {u[3]} | {u[4]} | {u[5]}")
else:
print("β No users found in database")
# Check automated bookings
print("\n3. Checking automated bookings:")
bookings = conn.execute("""
SELECT booking_id, user_account, professional_id, risk_level, risk_score
FROM automated_bookings
WHERE user_account = 'Mugisha'
ORDER BY created_ts DESC
LIMIT 5
""").fetchall()
if bookings:
print(f"Found {len(bookings)} bookings for Mugisha:")
for b in bookings:
print(f" {b[0]} | {b[1]} | {b[2]} | {b[3]} | {b[4]}")
else:
print("β No bookings found for Mugisha")
# Test the exact query from the API
print("\n4. Testing API query:")
test_query = conn.execute("""
SELECT ab.booking_id, ab.conv_id, ab.user_account, ab.user_ip, ab.risk_level, ab.risk_score,
ab.detected_indicators, ab.conversation_summary, ab.booking_status,
ab.scheduled_datetime, ab.session_type, ab.created_ts, ab.updated_ts,
u.fullname, u.email, u.telephone, u.province, u.district, u.created_at
FROM automated_bookings ab
LEFT JOIN users u ON ab.user_account = u.username
WHERE ab.booking_id = ? AND ab.professional_id = ?
""", ('d63a7794-a89c-452c-80a6-24691e3cb848', '6')).fetchone()
if test_query:
print("β
API query successful!")
print(f" Booking ID: {test_query[0]}")
print(f" User Account: {test_query[2]}")
print(f" Full Name: {test_query[13]}")
print(f" Email: {test_query[14]}")
print(f" Phone: {test_query[15]}")
print(f" Province: {test_query[16]}")
print(f" District: {test_query[17]}")
print(f" Created At: {test_query[18]}")
else:
print("β API query failed - no results")
conn.close()
except Exception as e:
print(f"β Database Error: {e}")
if __name__ == "__main__":
check_user_data()
|