membershipworks: Scrape folder membership from membershipworks api
This commit is contained in:
parent
dfacf813e2
commit
0a92c28efc
@ -7,10 +7,12 @@ from membershipworks import MembershipWorks
|
|||||||
|
|
||||||
|
|
||||||
class Command(BaseCommand):
|
class Command(BaseCommand):
|
||||||
def flags_for_member(self, csv_member, all_flags):
|
def flags_for_member(self, csv_member, all_flags, folders):
|
||||||
# update member's flags
|
|
||||||
for flag in all_flags:
|
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:
|
if csv_member[flag.name] == flag.name:
|
||||||
yield flag
|
yield flag
|
||||||
|
|
||||||
@ -31,6 +33,14 @@ class Command(BaseCommand):
|
|||||||
print("Updating flags (labels, levels, and addons)")
|
print("Updating flags (labels, levels, and addons)")
|
||||||
flags = list(self.update_flags(membershipworks._parse_flags()))
|
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...")
|
print("Getting/Updating members...")
|
||||||
members = membershipworks.get_all_members()
|
members = membershipworks.get_all_members()
|
||||||
for csv_member in members:
|
for csv_member in members:
|
||||||
@ -45,4 +55,4 @@ class Command(BaseCommand):
|
|||||||
member = Member.from_csv_dict(csv_member)
|
member = Member.from_csv_dict(csv_member)
|
||||||
member.clean_fields()
|
member.clean_fields()
|
||||||
member.save()
|
member.save()
|
||||||
member.flags.set(self.flags_for_member(csv_member, flags))
|
member.flags.set(self.flags_for_member(csv_member, flags, folders))
|
||||||
|
Loading…
Reference in New Issue
Block a user