diff --git a/sqlExport.py b/sqlExport.py index c263b12..e55a6ed 100644 --- a/sqlExport.py +++ b/sqlExport.py @@ -31,14 +31,15 @@ def insertFromTableMap(table, data, tableMap): # TODO: delete non-valid labels def insertLabels(members): - def formatLabels(labels): - for member in members: - for label, label_id in membershipworks._parse_flags()['labels'].items(): - if member[label]: - yield member['Account ID'], label_id + for member in members: + for label, label_id in membershipworks._parse_flags()['labels'].items(): + if member[label]: + c.execute('REPLACE INTO member_labels (uid, label_id) VALUES (%s, %s);', + (member['Account ID'], label_id)) + else: + c.execute('DELETE FROM member_labels WHERE uid=%s && label_id=%s;', + (member['Account ID'], label_id)) - c.executemany('REPLACE INTO member_labels (uid, label_id) VALUES (%s, %s);', - list(formatLabels(members))) with open('tableMapping.yaml') as f: tableMapping = yaml.load(f, yaml.SafeLoader)