sqlExport: Delete labels that are no longer valid
This commit is contained in:
parent
b82da10073
commit
01e08e1007
@ -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
|
||||
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)
|
||||
|
Reference in New Issue
Block a user