mirror of
https://github.com/tmdinosaurcenter/kiosk-guestbook.git
synced 2025-04-10 14:11:28 -06:00
Updated guestbook_export.py so that the export
This commit is contained in:
parent
5d71d778f8
commit
79bbb02388
@ -1,24 +1,25 @@
|
|||||||
import csv
|
import csv
|
||||||
import sqlite3
|
import sqlite3
|
||||||
|
|
||||||
|
# Update the database file path if needed.
|
||||||
DATABASE = 'guestbook.db'
|
DATABASE = 'guestbook.db'
|
||||||
EXPORT_FILE = 'mailchimp_export.csv'
|
EXPORT_FILE = 'mailchimp_export.csv'
|
||||||
|
|
||||||
def export_guestbook_to_csv():
|
def export_guestbook_to_csv():
|
||||||
conn = sqlite3.connect(DATABASE)
|
conn = sqlite3.connect(DATABASE)
|
||||||
cursor = conn.cursor()
|
cursor = conn.cursor()
|
||||||
# Select only entries that have an email address (if that's required)
|
# Select only entries that have an email address, if that's required.
|
||||||
cursor.execute('''
|
cursor.execute('''
|
||||||
SELECT email, first_name, last_name
|
SELECT email, first_name, last_name, comment
|
||||||
FROM guests
|
FROM guests
|
||||||
WHERE email IS NOT NULL AND email <> ''
|
WHERE email IS NOT NULL AND email <> ''
|
||||||
''')
|
''')
|
||||||
rows = cursor.fetchall()
|
rows = cursor.fetchall()
|
||||||
|
|
||||||
with open(EXPORT_FILE, 'w', newline='') as csvfile:
|
with open(EXPORT_FILE, 'w', newline='', encoding='utf-8') as csvfile:
|
||||||
writer = csv.writer(csvfile)
|
writer = csv.writer(csvfile)
|
||||||
# Write headers matching Mailchimp's expected column names
|
# Write headers matching Mailchimp's expected column names (and including comment)
|
||||||
writer.writerow(['Email Address', 'First Name', 'Last Name'])
|
writer.writerow(['Email Address', 'First Name', 'Last Name', 'Comment'])
|
||||||
for row in rows:
|
for row in rows:
|
||||||
writer.writerow(row)
|
writer.writerow(row)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user