-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfetch_attendees.py
More file actions
93 lines (74 loc) · 2.59 KB
/
fetch_attendees.py
File metadata and controls
93 lines (74 loc) · 2.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
"""Fetch attendees for an event.
Gets the attendee list for a specific event, showing attendance and payment status.
Usage:
export HELLOCLUB_API_KEY="your-api-key-here"
python examples/fetch_attendees.py [event_id]
If no event_id is provided, fetches the next upcoming event and uses that.
"""
from __future__ import annotations
import os
import sys
from datetime import datetime, timedelta, timezone
import httpx
API_KEY = os.environ["HELLOCLUB_API_KEY"]
BASE_URL = "https://api.helloclub.com"
HEADERS = {"X-Api-Key": API_KEY}
def get_next_event() -> dict | None:
"""Find the next upcoming event."""
now = datetime.now(timezone.utc)
resp = httpx.get(
f"{BASE_URL}/event",
headers=HEADERS,
params={
"fromDate": now.strftime("%Y-%m-%dT%H:%M:%SZ"),
"toDate": (now + timedelta(days=30)).strftime("%Y-%m-%dT%H:%M:%SZ"),
"sort": "startDate",
"limit": 1,
},
)
resp.raise_for_status()
events = resp.json().get("events", [])
return events[0] if events else None
def get_attendees(event_id: str) -> list[dict]:
"""Fetch all attendees for an event."""
resp = httpx.get(
f"{BASE_URL}/eventAttendee",
headers=HEADERS,
params={"event": event_id, "limit": 100},
)
resp.raise_for_status()
data = resp.json()
return data.get("attendees", []) if isinstance(data, dict) else data
# Determine event ID
event_id = sys.argv[1] if len(sys.argv) > 1 else None
if not event_id:
event = get_next_event()
if not event:
print("No upcoming events found.")
sys.exit(0)
event_id = event["id"]
print(f"Using next event: {event['name']} ({event['startDate'][:10]})")
print()
# Fetch and display attendees
attendees = get_attendees(event_id)
print(f"Attendees: {len(attendees)}\n")
print(f"{'Name':<25} {'Type':<8} {'Attended':<10} {'Paid':<6} {'Fee'}")
print("-" * 65)
for att in attendees:
name = f"{att['firstName']} {att['lastName']}"[:24]
att_type = "Guest" if att.get("isGuest") else "Member"
attended = "Yes" if att.get("hasAttended") else "No"
paid = "Yes" if att.get("isPaid") else "No"
# Parse fee from rule
rule = att.get("rule", {})
rule_type = rule.get("type", "")
fee = rule.get("fee", 0)
if att.get("hasMembershipRule") or rule_type == "membership":
fee_str = "Membership"
elif rule_type == "fee" and fee:
fee_str = f"${fee:.2f}"
elif rule_type == "free":
fee_str = "Free"
else:
fee_str = ""
print(f" {name:<25} {att_type:<8} {attended:<10} {paid:<6} {fee_str}")