Files
FitTrack2/FitnessSync/scratch/inspect_db_tokens_standalone.py
2026-01-09 09:59:36 -08:00

42 lines
1.2 KiB
Python

import os
import sys
from sqlalchemy import create_engine, text
from sqlalchemy.orm import sessionmaker
# Hardcode DB URL from docker-compose.yml
# DATABASE_URL=postgresql://postgres:password@db:5432/fitbit_garmin_sync
DATABASE_URL = "postgresql://postgres:password@db:5432/fitbit_garmin_sync"
engine = create_engine(DATABASE_URL)
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
def inspect_tokens():
db = SessionLocal()
try:
# Use raw SQL to avoid needing model definitions
result = db.execute(text("SELECT token_type, garth_oauth1_token, garth_oauth2_token, updated_at FROM api_tokens WHERE token_type='garmin'"))
row = result.fetchone()
if not row:
print("No Garmin token record found.")
return
print(f"Token Type: {row[0]}")
print(f"Updated At: {row[3]}")
print("-" * 40)
print("OAuth1 Token Raw:")
print(row[1])
print("-" * 40)
print("OAuth2 Token Raw:")
print(row[2])
print("-" * 40)
except Exception as e:
print(f"Error inspecting tokens: {e}")
finally:
db.close()
if __name__ == "__main__":
inspect_tokens()