50 lines
1.5 KiB
Python
50 lines
1.5 KiB
Python
|
|
import os
|
|
import sys
|
|
import psycopg2
|
|
from dotenv import load_dotenv
|
|
|
|
# Load env vars
|
|
load_dotenv('/Users/daveporter/Desktop/CODING-2024/Ferrero-Opentext/Python-Version/.env')
|
|
|
|
try:
|
|
conn = psycopg2.connect(
|
|
host=os.getenv('DB_HOST', 'localhost'),
|
|
port=os.getenv('DB_PORT', '5437'),
|
|
database='ferrero_tracking',
|
|
user=os.getenv('DB_USER'),
|
|
password=os.getenv('DB_PASSWORD')
|
|
)
|
|
cursor = conn.cursor()
|
|
|
|
print("--- Tables ---")
|
|
cursor.execute("SELECT table_name FROM information_schema.tables WHERE table_schema = 'public'")
|
|
for table in cursor.fetchall():
|
|
print(table[0])
|
|
|
|
print("\n--- campaign_status content ---")
|
|
try:
|
|
cursor.execute("SELECT * FROM campaign_status")
|
|
columns = [desc[0] for desc in cursor.description]
|
|
print(", ".join(columns))
|
|
rows = cursor.fetchall()
|
|
for row in rows:
|
|
print(row)
|
|
if not rows:
|
|
print("(No rows)")
|
|
except Exception as e:
|
|
print(f"Error querying campaign_status: {e}")
|
|
|
|
print("\n--- master_assets content (limit 5) ---")
|
|
try:
|
|
cursor.execute("SELECT tracking_id, opentext_id, local_campaign_id FROM master_assets LIMIT 5")
|
|
columns = [desc[0] for desc in cursor.description]
|
|
print(", ".join(columns))
|
|
for row in cursor.fetchall():
|
|
print(row)
|
|
except Exception as e:
|
|
print(f"Error querying master_assets: {e}")
|
|
|
|
conn.close()
|
|
except Exception as e:
|
|
print(f"Connection failed: {e}")
|