import os
import psycopg2
from dotenv import load_dotenv

load_dotenv()

def check_data():
    try:
        conn = psycopg2.connect(
            host=os.getenv("DB_HOST"),
            port=os.getenv("DB_PORT"),
            database=os.getenv("DB_NAME"),
            user=os.getenv("DB_USER"),
            password=os.getenv("DB_PASSWORD")
        )
        with conn.cursor() as cur:
            cur.execute("SELECT count(*) FROM google_review;")
            count = cur.fetchone()[0]
            print(f"Total reviews in 'google_review' table: {count}")
            
            cur.execute("SELECT author_display_name, rating, publish_time, outlet_code, language, original_text FROM google_review ORDER BY created_at DESC LIMIT 5;")
            rows = cur.fetchall()
            for row in rows:
                print(row)
        conn.close()
    except Exception as e:
        print(f"Error checking data: {e}")

if __name__ == "__main__":
    check_data()
