membershipworks: Add support for scraping event registration data

This commit is contained in:
Adam Goldsmith 2024-04-30 14:34:45 -04:00
parent 12eb4038bc
commit ee2d63f784
4 changed files with 41 additions and 0 deletions

View File

@ -269,6 +269,22 @@ class MembershipWorks:
) )
return r.json() return r.json()
def get_event_registrations(self, event_id: str):
r = self._get_v1(
BASE_URL + "/v1/csv",
params={
"_rt": "946702800", # unknown
"evt": event_id,
},
)
if r.status_code != requests.codes.ok:
raise MembershipWorksRemoteError("csv generation", r)
if r.text[0] == "\ufeff":
r.encoding = r.encoding + "-sig"
return list(csv.DictReader(StringIO(r.text)))
def get_event_by_url(self, url: str): def get_event_by_url(self, url: str):
"""Retrieve a specific event by its url""" """Retrieve a specific event by its url"""
r = self.sess.get( r = self.sess.get(

View File

@ -0,0 +1,22 @@
# Generated by Django 5.0.4 on 2024-04-30 05:07
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
("membershipworks", "0016_eventinvoice"),
]
operations = [
migrations.AddField(
model_name="eventext",
name="registrations",
field=models.JSONField(blank=True, null=True),
),
migrations.AlterField(
model_name="eventinvoice",
name="pdf",
field=models.FileField(upload_to="protected/invoices/%Y/%m/%d/"),
),
]

View File

@ -551,6 +551,7 @@ class EventExt(Event):
max_digits=13, decimal_places=4, default=0 max_digits=13, decimal_places=4, default=0
) )
details = models.JSONField(null=True, blank=True) details = models.JSONField(null=True, blank=True)
registrations = models.JSONField(null=True, blank=True)
def get_absolute_url(self) -> str: def get_absolute_url(self) -> str:
return reverse("membershipworks:event-detail", kwargs={"eid": self.eid}) return reverse("membershipworks:event-detail", kwargs={"eid": self.eid})

View File

@ -110,6 +110,7 @@ def scrape_event_details(queryset: QuerySet[EventExt]):
for event in queryset: for event in queryset:
event.details = membershipworks.get_event_by_eid(event.eid) event.details = membershipworks.get_event_by_eid(event.eid)
event.registrations = membershipworks.get_event_registrations(event.eid)
event.save() event.save()
@ -171,4 +172,5 @@ def scrape_events():
event_ext.end or event_ext.start event_ext.end or event_ext.start
): ):
event_ext.details = membershipworks.get_event_by_eid(event.eid) event_ext.details = membershipworks.get_event_by_eid(event.eid)
event_ext.registrations = membershipworks.get_event_registrations(event.eid)
event_ext.save() event_ext.save()