membershipworks: Add support for scraping event registration data
This commit is contained in:
parent
12eb4038bc
commit
ee2d63f784
@ -269,6 +269,22 @@ class MembershipWorks:
|
||||
)
|
||||
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):
|
||||
"""Retrieve a specific event by its url"""
|
||||
r = self.sess.get(
|
||||
|
@ -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/"),
|
||||
),
|
||||
]
|
@ -551,6 +551,7 @@ class EventExt(Event):
|
||||
max_digits=13, decimal_places=4, default=0
|
||||
)
|
||||
details = models.JSONField(null=True, blank=True)
|
||||
registrations = models.JSONField(null=True, blank=True)
|
||||
|
||||
def get_absolute_url(self) -> str:
|
||||
return reverse("membershipworks:event-detail", kwargs={"eid": self.eid})
|
||||
|
@ -110,6 +110,7 @@ def scrape_event_details(queryset: QuerySet[EventExt]):
|
||||
|
||||
for event in queryset:
|
||||
event.details = membershipworks.get_event_by_eid(event.eid)
|
||||
event.registrations = membershipworks.get_event_registrations(event.eid)
|
||||
event.save()
|
||||
|
||||
|
||||
@ -171,4 +172,5 @@ def scrape_events():
|
||||
event_ext.end or event_ext.start
|
||||
):
|
||||
event_ext.details = membershipworks.get_event_by_eid(event.eid)
|
||||
event_ext.registrations = membershipworks.get_event_registrations(event.eid)
|
||||
event_ext.save()
|
||||
|
Loading…
Reference in New Issue
Block a user