membershipworks: Move member and transaction scraping into separate functions

This commit is contained in:
Adam Goldsmith 2022-03-02 17:24:48 -05:00
parent 02c9be5ae6
commit ea94d9a3df

View File

@ -25,13 +25,7 @@ class Command(BaseCommand):
flag.save()
yield flag
@transaction.atomic()
def handle(self, *args, **options):
membershipworks = MembershipWorks()
membershipworks.login(
settings.MEMBERSHIPWORKS_USERNAME, settings.MEMBERSHIPWORKS_PASSWORD
)
def scrape_members(self, membershipworks: MembershipWorks):
print("Updating flags (labels, levels, and addons)")
flags = list(self.update_flags(membershipworks._parse_flags()))
@ -59,6 +53,7 @@ class Command(BaseCommand):
member.save()
member.flags.set(self.flags_for_member(csv_member, flags, folders))
def scrape_transactions(self, membershipworks: MembershipWorks):
now = datetime.now()
start_date = datetime(2010, 1, 1)
last_transaction = Transaction.objects.order_by("timestamp").last()
@ -83,3 +78,13 @@ class Command(BaseCommand):
for csv_transaction in transactions:
Transaction.from_csv_dict(csv_transaction).save()
@transaction.atomic()
def handle(self, *args, **options):
membershipworks = MembershipWorks()
membershipworks.login(
settings.MEMBERSHIPWORKS_USERNAME, settings.MEMBERSHIPWORKS_PASSWORD
)
self.scrape_members(membershipworks)
self.scrape_transactions(membershipworks)