From 363be0ba8c22bff29a8e8bbc81fa777a7c1b2c35 Mon Sep 17 00:00:00 2001 From: Adam Goldsmith Date: Tue, 3 Jan 2023 16:20:52 -0500 Subject: [PATCH] sqlExport: Get folder membership and apply into memberflags --- memberPlumbing/sqlExport.py | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/memberPlumbing/sqlExport.py b/memberPlumbing/sqlExport.py index a3d5cc3..1e04c03 100755 --- a/memberPlumbing/sqlExport.py +++ b/memberPlumbing/sqlExport.py @@ -22,6 +22,12 @@ def do_import(config): ] ).on_conflict(action="update", preserve=[Flag.name, Flag.type]).execute() + print("Getting folder membership...") + folders = { + folder_id: membershipworks.get_member_ids([folder_name]) + for folder_name, folder_id in membershipworks._parse_flags()["folders"].items() + } + print("Getting/Updating members...") members = membershipworks.get_all_members() for m in members: @@ -41,13 +47,14 @@ def do_import(config): # update member's flags for type, flags in membershipworks._parse_flags().items(): - if type != "folders": # currently no way to retrieve this info - for flag, id in flags.items(): - ml = MemberFlag(uid=member["Account ID"], flag_id=id) - if member[flag]: - ml.magic_save() - else: - ml.delete_instance() + for flag, id in flags.items(): + ml = MemberFlag(uid=member["Account ID"], flag_id=id) + if (type == "folders" and member["Account ID"] in folders[id]) or ( + type != "folders" and member[flag] + ): + ml.magic_save() + else: + ml.delete_instance() print("Getting/Updating transactions...") # Deduping these is hard, so just recreate the data every time