From 0a92c28efc29d39116034326ccbef48324bb0f13 Mon Sep 17 00:00:00 2001 From: Adam Goldsmith Date: Mon, 28 Feb 2022 17:16:32 -0500 Subject: [PATCH] membershipworks: Scrape folder membership from membershipworks api --- .../commands/scrape_membershipworks.py | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/membershipworks/management/commands/scrape_membershipworks.py b/membershipworks/management/commands/scrape_membershipworks.py index c311a40..c4eddbb 100644 --- a/membershipworks/management/commands/scrape_membershipworks.py +++ b/membershipworks/management/commands/scrape_membershipworks.py @@ -7,10 +7,12 @@ from membershipworks import MembershipWorks class Command(BaseCommand): - def flags_for_member(self, csv_member, all_flags): - # update member's flags + def flags_for_member(self, csv_member, all_flags, folders): for flag in all_flags: - if flag.type != "folder": # currently no way to retrieve this info + if flag.type == "folder": + if csv_member["Account ID"] in folders[flag.id]: + yield flag + else: if csv_member[flag.name] == flag.name: yield flag @@ -31,6 +33,14 @@ class Command(BaseCommand): print("Updating flags (labels, levels, and addons)") flags = list(self.update_flags(membershipworks._parse_flags())) + 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 csv_member in members: @@ -45,4 +55,4 @@ class Command(BaseCommand): member = Member.from_csv_dict(csv_member) member.clean_fields() member.save() - member.flags.set(self.flags_for_member(csv_member, flags)) + member.flags.set(self.flags_for_member(csv_member, flags, folders))