Skip to content

Commit e8299fe

Browse files
committed
Improve the meetup script venue detection
1 parent 07acd61 commit e8299fe

File tree

3 files changed

+32
-17
lines changed

3 files changed

+32
-17
lines changed

tools/events/meetup-automation/event.py

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ class Event:
7676
virtual: bool
7777
organizer_name: str
7878
organizer_url: str
79+
no_venue: bool
7980

8081
def __post_init__(self):
8182
""" Normalize the event data here """
@@ -91,7 +92,8 @@ def to_dict(self) -> dict:
9192
"url": self.url,
9293
"virtual": self.virtual,
9394
"organizer_name": self.organizer_name,
94-
"organizer_url": self.organizer_url
95+
"organizer_url": self.organizer_url,
96+
"no_venue": self.no_venue
9597
}
9698

9799
def to_markdown_string(self) -> str:
@@ -111,9 +113,9 @@ class RawGqlEvent:
111113
date_time_str: str
112114
event_url_str: str
113115
venue_type: None | str
114-
event_location: Location
115-
lat: float
116-
long: float
116+
event_location: None | Location
117+
lat: None | float
118+
long: None | float
117119

118120
def __init__(self, **kwargs) -> None:
119121
logger.debug(f"Constructing RawGqlEvent from: {kwargs}")
@@ -128,22 +130,29 @@ def __init__(self, **kwargs) -> None:
128130
self.date_time_str = node["dateTime"]
129131
self.event_url_str = node["eventUrl"]
130132

131-
venue = node["venue"]
132-
self.venue_type = venue["venueType"]
133-
# TODO: do we need these lat longs?
134-
self.lat = venue["lat"]
135-
self.long = venue["lng"]
136-
self.event_location = Location(venue["city"], venue["state"], venue["country"])
133+
if node["venue"]:
134+
venue = node["venue"]
135+
self.venue_type = venue["venueType"]
136+
# TODO: do we need these lat longs?
137+
self.lat = venue["lat"]
138+
self.long = venue["lng"]
139+
self.event_location = Location(venue["city"], venue["state"], venue["country"])
140+
else:
141+
self.event_location = None
142+
self.venue_type = None
143+
self.lat = None
144+
self.long = None
137145

138146
def to_event(self, group_url: str) -> Event:
139-
is_virtual = self.venue_type == "online"
147+
is_virtual = self.venue_type is not None and self.venue_type == "online"
148+
no_venue = self.event_location is None
140149

141150
# this is a bit weird because we want a naive datetime object that just contains the year/month/day because we get
142151
# timestamps with tz info like "2025-01-16T19:00+01:00", just strip the time and tz info before parsing
143152
date = datetime.strptime(self.date_time_str.split('T')[0], '%Y-%m-%d')
144153

145154
# prefer the event specific location, otherwise fall back to the group's location
146-
if self.event_location.fields_present() > self.group_location.fields_present():
155+
if self.event_location and self.event_location.fields_present() > self.group_location.fields_present():
147156
location = self.event_location
148157
else:
149158
location = self.group_location
@@ -155,6 +164,6 @@ def to_event(self, group_url: str) -> Event:
155164
url=self.event_url_str,
156165
virtual=is_virtual,
157166
organizer_name=self.group_name,
158-
organizer_url=group_url
167+
organizer_url=group_url,
168+
no_venue=no_venue
159169
)
160-

tools/events/meetup-automation/generate_events_meetup.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,7 @@ def _parse_event_listing_gql_response(self, response: dict) -> List[RawGqlEvent]
103103
# TODO: maybe move this validation somewhere else?
104104
for edge_kwargs in edges:
105105
if not edge_kwargs["node"]["venue"]:
106-
logger.error(f"Event response missing venue: {edge_kwargs}")
107-
continue
106+
logger.info(f"Event response missing venue: {edge_kwargs}")
108107

109108
events.append(RawGqlEvent(**edge_kwargs))
110109

tools/events/meetup-automation/main.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,11 +105,18 @@ def group_virtual_continent(event_list):
105105

106106
for event in event_list:
107107
# Separates Events by Virtual or by Continent
108-
key = "Virtual" if event.virtual else country_code_to_continent(event.location.country)
108+
key = determine_event_key(event)
109109
separated_event_list.setdefault(key, []).append(event)
110110

111111
return separated_event_list
112112

113+
def determine_event_key(event: Event):
114+
if event.virtual:
115+
return "Virtual"
116+
elif event.no_venue:
117+
return "No Venue"
118+
else:
119+
return country_code_to_continent(event.location.country)
113120

114121
def remove_duplicate_events(events: List[Event]) -> List[Event]:
115122
# Identifies possible duplicate Events within Event List.

0 commit comments

Comments
 (0)