Created a script to update the csv imports that don't have the date
This commit is contained in:
36
fetch_and_update_leads.py
Normal file
36
fetch_and_update_leads.py
Normal file
@@ -0,0 +1,36 @@
|
||||
import psycopg2
|
||||
from psycopg2.extras import RealDictCursor
|
||||
import json
|
||||
import csv
|
||||
from datetime import datetime
|
||||
|
||||
# Database connection
|
||||
conn = psycopg2.connect(
|
||||
dbname="meta_insights",
|
||||
user="meta_user",
|
||||
password="meta_password",
|
||||
host="localhost",
|
||||
port=5555
|
||||
)
|
||||
|
||||
# Set search path to the schema
|
||||
cursor = conn.cursor(cursor_factory=RealDictCursor)
|
||||
cursor.execute("SET search_path TO alpinebits")
|
||||
|
||||
# Fetch the data
|
||||
cursor.execute("""
|
||||
select r.id, r.created_at, r.customer_id, r.unique_id,
|
||||
c.given_name, c.email
|
||||
from reservations as r
|
||||
join customers as c on c.id = r.customer_id
|
||||
where unique_id like 'csv_%'
|
||||
order by r.created_at desc
|
||||
""")
|
||||
|
||||
rows = cursor.fetchall()
|
||||
print(f"Found {len(rows)} rows to update")
|
||||
for row in rows:
|
||||
print(f" - {row['given_name']} ({row['email']}): {row['created_at']}")
|
||||
|
||||
cursor.close()
|
||||
conn.close()
|
||||
Reference in New Issue
Block a user