sqlExport: Delete labels that are no longer valid

This commit is contained in:
Adam Goldsmith 2020-02-19 15:24:55 -05:00
parent b82da10073
commit 01e08e1007

View File

@ -31,14 +31,15 @@ def insertFromTableMap(table, data, tableMap):
# TODO: delete non-valid labels # TODO: delete non-valid labels
def insertLabels(members): def insertLabels(members):
def formatLabels(labels): for member in members:
for member in members: for label, label_id in membershipworks._parse_flags()['labels'].items():
for label, label_id in membershipworks._parse_flags()['labels'].items(): if member[label]:
if member[label]: c.execute('REPLACE INTO member_labels (uid, label_id) VALUES (%s, %s);',
yield member['Account ID'], label_id (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: with open('tableMapping.yaml') as f:
tableMapping = yaml.load(f, yaml.SafeLoader) tableMapping = yaml.load(f, yaml.SafeLoader)