membershipworks: Get only transactions since last in database + 1 second

This avoids having to deduplicate transactions, at the cost of
hypothetically missing transactions in some unlikely edge cases
This commit is contained in:
Adam Goldsmith 2022-03-02 17:19:36 -05:00
parent 7563e5dcea
commit 02c9be5ae6

View File

@ -1,4 +1,4 @@
from datetime import datetime from datetime import datetime, timedelta
from django.conf import settings from django.conf import settings
from django.core.management.base import BaseCommand from django.core.management.base import BaseCommand
@ -59,11 +59,16 @@ class Command(BaseCommand):
member.save() member.save()
member.flags.set(self.flags_for_member(csv_member, flags, folders)) member.flags.set(self.flags_for_member(csv_member, flags, folders))
print("Getting/Updating transactions...")
# Deduping these is hard, so just recreate the data every time
Transaction.objects.all().delete()
now = datetime.now() now = datetime.now()
start_date = datetime(2010, 1, 1) start_date = datetime(2010, 1, 1)
last_transaction = Transaction.objects.order_by("timestamp").last()
if last_transaction is not None:
# technically this has the potential to lose
# transactions, but it should be incredibly unlikely
start_date = last_transaction.timestamp + timedelta(seconds=1)
print(f"Getting/Updating transactions since {start_date}...")
transactions_csv = membershipworks.get_transactions(start_date, now) transactions_csv = membershipworks.get_transactions(start_date, now)
transactions_json = membershipworks.get_transactions(start_date, now, json=True) transactions_json = membershipworks.get_transactions(start_date, now, json=True)
# this is terrible, but as long as the dates are the same, should be fiiiine # this is terrible, but as long as the dates are the same, should be fiiiine