forked from CMS/memberPlumbing
sqlExport: Add some informational prints
This commit is contained in:
parent
a6e596cfd4
commit
6ab2b7bd9c
15
sqlExport.py
15
sqlExport.py
@ -64,6 +64,7 @@ def createDefinitionsFromTableMap(tableMap):
|
|||||||
for k, v in tableMap.items()])
|
for k, v in tableMap.items()])
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
print("Creating tables...")
|
||||||
c.execute('CREATE TABLE IF NOT EXISTS members (' +
|
c.execute('CREATE TABLE IF NOT EXISTS members (' +
|
||||||
createDefinitionsFromTableMap(tableMapping['members']) +
|
createDefinitionsFromTableMap(tableMapping['members']) +
|
||||||
') WITH SYSTEM VERSIONING;')
|
') WITH SYSTEM VERSIONING;')
|
||||||
@ -84,6 +85,13 @@ try:
|
|||||||
FOREIGN KEY(label_id) REFERENCES labels(label_id)
|
FOREIGN KEY(label_id) REFERENCES labels(label_id)
|
||||||
) WITH SYSTEM VERSIONING;""")
|
) WITH SYSTEM VERSIONING;""")
|
||||||
|
|
||||||
|
print("Updating labels")
|
||||||
|
c.executemany("""INSERT INTO labels (label, label_id) VALUES (%s, %s)
|
||||||
|
ON DUPLICATE KEY UPDATE
|
||||||
|
label=VALUES(label), label_id=VALUES(label_id);""",
|
||||||
|
membershipworks._parse_flags()['labels'].items())
|
||||||
|
|
||||||
|
print("Getting/Updating members...")
|
||||||
members = membershipworks.get_all_members()
|
members = membershipworks.get_all_members()
|
||||||
for m in members:
|
for m in members:
|
||||||
# replace flags by booleans
|
# replace flags by booleans
|
||||||
@ -96,18 +104,15 @@ try:
|
|||||||
if field.get('typ') == 8 and field['lbl'] in m: # check box
|
if field.get('typ') == 8 and field['lbl'] in m: # check box
|
||||||
m[field['lbl']] = True if m[field['lbl']] == 'Y' else False
|
m[field['lbl']] = True if m[field['lbl']] == 'Y' else False
|
||||||
|
|
||||||
c.executemany("""INSERT INTO labels (label, label_id) VALUES (%s, %s)
|
|
||||||
ON DUPLICATE KEY UPDATE
|
|
||||||
label=VALUES(label), label_id=VALUES(label_id);""",
|
|
||||||
membershipworks._parse_flags()['labels'].items())
|
|
||||||
|
|
||||||
insertFromTableMap('members', members, tableMapping['members'])
|
insertFromTableMap('members', members, tableMapping['members'])
|
||||||
|
|
||||||
insertLabels(members)
|
insertLabels(members)
|
||||||
|
|
||||||
|
print("Getting/Updating transactions...")
|
||||||
transactions = membershipworks.get_transactions(datetime(2020, 1, 1), datetime.now())
|
transactions = membershipworks.get_transactions(datetime(2020, 1, 1), datetime.now())
|
||||||
insertFromTableMap('transactions', transactions, tableMapping['transactions'])
|
insertFromTableMap('transactions', transactions, tableMapping['transactions'])
|
||||||
|
|
||||||
|
print("Committing changes...")
|
||||||
conn.commit()
|
conn.commit()
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
Loading…
Reference in New Issue
Block a user