membershipworks: Scrape folder membership from membershipworks api

This commit is contained in:
Adam Goldsmith 2022-02-28 17:16:32 -05:00
parent dfacf813e2
commit 0a92c28efc

View File

@ -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))