From b51f88344dc6e5a1363d221ccca0c2ab96dccbab Mon Sep 17 00:00:00 2001 From: Steve Dogiakos Date: Tue, 1 Apr 2025 18:48:04 -0600 Subject: [PATCH] Created guestbook_export.py which is tailored specifically toward exporting for MailChimp --- scripts/guestbook_export.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 scripts/guestbook_export.py diff --git a/scripts/guestbook_export.py b/scripts/guestbook_export.py new file mode 100644 index 0000000..21bf00b --- /dev/null +++ b/scripts/guestbook_export.py @@ -0,0 +1,29 @@ +import csv +import sqlite3 + +DATABASE = 'guestbook.db' +EXPORT_FILE = 'mailchimp_export.csv' + +def export_guestbook_to_csv(): + conn = sqlite3.connect(DATABASE) + cursor = conn.cursor() + # Select only entries that have an email address (if that's required) + cursor.execute(''' + SELECT email, first_name, last_name + FROM guests + WHERE email IS NOT NULL AND email <> '' + ''') + rows = cursor.fetchall() + + with open(EXPORT_FILE, 'w', newline='') as csvfile: + writer = csv.writer(csvfile) + # Write headers matching Mailchimp's expected column names + writer.writerow(['Email Address', 'First Name', 'Last Name']) + for row in rows: + writer.writerow(row) + + conn.close() + print(f"Export completed: {EXPORT_FILE}") + +if __name__ == '__main__': + export_guestbook_to_csv()