diff --git a/memberPlumbing/upcomingEvents.py b/memberPlumbing/upcomingEvents.py
index 54cf770..a038786 100644
--- a/memberPlumbing/upcomingEvents.py
+++ b/memberPlumbing/upcomingEvents.py
@@ -3,48 +3,79 @@
from datetime import datetime
from .config import Config
-from .MembershipWorks import MembershipWorks
-def format_event(membershipworks: MembershipWorks, event):
- event_details = membershipworks.get_event_by_eid(event["eid"])
+def format_event(event_details, truncate: bool):
url = (
"https://claremontmakerspace.org/events/#!event/register/"
+ event_details["url"]
)
if "lgo" in event_details:
- img = f""""""
+ img = (
+ f""""""
+ )
else:
img = ""
# print(json.dumps(event_details))
- return f"""
-
- {img}
- {event_details['ttl']}
-
+ out = f"""
-
{event_details['szp']} — {event_details['ezp']}
+{event_details['szp']} — {event_details['ezp']}
+"""
+ if not truncate:
+ out += f"""
{event_details['dtl']}
Register for this class now!"""
+ return out
+
+
+def format_section(title: str, blurb: str, events, truncate: bool):
+ # skip empty sections
+ if not events:
+ return ""
+
+ events_list = "\n
\n\n".join(format_event(event, truncate) for event in events)
+
+ return f"""{title}
+{blurb}
+{events_list}
+"""
def main():
config = Config()
+ now = datetime.now()
membershipworks = config.membershipworks
- events = membershipworks.get_events_list(datetime.now())
+ events = membershipworks.get_events_list(now)
if "error" in events:
print("Error:", events["error"])
return
- events_list = "\n
\n\n".join(
- format_event(membershipworks, event)
- for event in events["evt"]
- if event["cal"] != 0 # ignore hidden events
- )
+ ongoing_events = []
+ full_events = []
+ upcoming_events = []
+ for event in events["evt"]:
+ # ignore hidden events
+ if event["cal"] == 0:
+ continue
+ event_details = membershipworks.get_event_by_eid(event["eid"])
+
+ # registration has already ended
+ if (
+ "erd" in event_details
+ and datetime.fromtimestamp(event_details["erd"]) < now
+ ):
+ ongoing_events.append(event_details)
+ # class is full
+ elif event_details["cnt"] >= event_details["cap"]:
+ full_events.append(event_details)
+ else:
+ upcoming_events.append(event_details)
+
header = """
Greetings Upper Valley Makers:
We have an exciting list of upcoming classes at the Claremont MakerSpace that we think might interest you.
@@ -59,15 +90,40 @@ def main():
"""
- footer = """
-
+ footer = """
+
-
Happy Makin’!
-
We are grateful for all of the public support that our 501(c)(3), non-profit organization receives. If you’d like to make a donation,please visit the
Support Us page of our website.
+
Happy Makin’!
+
We are grateful for all of the public support that our 501(c)(3), non-profit organization receives. If you’d like to make a donation,please visit the
Support Us page of our website.
"""
- print(header, events_list, footer)
+ print(header)
+ print(
+ format_section(
+ "Upcoming Events",
+ "Events that are currently open for registration.",
+ upcoming_events,
+ truncate=False,
+ )
+ )
+ print(
+ format_section(
+ "Just Missed",
+ "These classes are currently full at time of writing. If you are interested, please check the event's page; spots occasionally open up. Keep an eye on this newsletter to see when these classes are offered again.",
+ full_events,
+ truncate=True,
+ )
+ )
+ print(
+ format_section(
+ "Ongoing",
+ "These classes are ongoing. Registration is closed, but they may be offered again in the future.",
+ ongoing_events,
+ truncate=True,
+ )
+ )
+ print(footer)
if __name__ == "__main__":