Skip to content

Commit b048fde

Browse files
committed
Generate list of Event for Meetup API & known Rush groups
1 parent ae71991 commit b048fde

File tree

1 file changed

+94
-2
lines changed

1 file changed

+94
-2
lines changed

tools/events-automation/generate_events_meetup.py

Lines changed: 94 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33
import concurrent.futures
44
import pandas as pd
55

6-
from generate_token import generate_signed_jwt
6+
from jwt_auth import generate_signed_jwt
77
from urllib.parse import urlsplit
8+
from event import Event
89

910
def authenticate():
1011
URL = "https://secure.meetup.com/oauth2/access"
@@ -132,4 +133,95 @@ def get_known_rush_groups(fileName):
132133
group["urlname"] = (split_url.path).replace("/", "")
133134
group["location"] = row["location"]
134135
groups[index] = group
135-
return groups
136+
return groups
137+
138+
def get_20_events(groups) -> list[Event]:
139+
# TODO: Make sure list of 20 events has all values for list of Event
140+
events = []
141+
URL = "https://api.meetup.com/gql"
142+
access_token, refresh_token = authenticate()
143+
144+
if not access_token:
145+
print("Authentication failed, cannot proceed to fetch events.")
146+
return
147+
148+
headers = {
149+
"Authorization": f"Bearer {access_token}",
150+
"Content-Type": "application/json",
151+
}
152+
data = {}
153+
count = 1
154+
for group in groups.values():
155+
urlName = group["urlname"]
156+
data = {
157+
"query": """
158+
query ($urlName: String!, $searchEventInput: ConnectionInput!) {
159+
groupByUrlname(urlname: $urlName) {
160+
upcomingEvents(input: $searchEventInput, sortOrder: ASC) {
161+
pageInfo {
162+
hasNextPage
163+
endCursor
164+
}
165+
edges {
166+
node {
167+
id
168+
title
169+
dateTime
170+
eventUrl
171+
venue {
172+
venueType
173+
lat
174+
lng
175+
}
176+
}
177+
}
178+
}
179+
}
180+
}
181+
""",
182+
"variables": {
183+
"urlName": urlName,
184+
"searchEventInput": {
185+
"first": 20
186+
}
187+
}
188+
}
189+
response = requests.post(url=URL, headers=headers, json=data)
190+
data = response.json()["data"]
191+
192+
if data:
193+
searchGroupByUrlname = data["groupByUrlname"]
194+
if searchGroupByUrlname:
195+
edges = searchGroupByUrlname["upcomingEvents"]["edges"]
196+
if edges:
197+
for edge in edges:
198+
node = edge["node"]
199+
if node:
200+
name = node["title"]
201+
lat, lng = 0, 0
202+
virtual = True
203+
venue = node["venue"]
204+
# TODO: What if venue is None? would it consider as spam event?
205+
if venue:
206+
lat, lng = venue["lat"], venue["lng"] # set to location?
207+
if venue["venueType"] != "online":
208+
virtual = False
209+
location = f"{lat}, {lng}"
210+
date = node["dateTime"]
211+
url = node["eventUrl"]
212+
organizerName = group.get("name", urlName)
213+
organizerUrl = group["link"]
214+
# print(f"Event({name}, location={location}\ndate={date}, url={url}, virtual={virtual}\norganizerName={organizerName}, organizerUrl={organizerUrl}\n")
215+
events.append(Event(name, location, date, url, virtual, organizerName, organizerUrl))
216+
return events
217+
218+
def get_events() -> list[Event]:
219+
# TODO: get list of events from Meetup and known Rush groups, and combine two list together
220+
# return the event source
221+
# groups = get_rush_groups()
222+
events_meetup_groups = get_20_events(get_rush_groups())
223+
# groups = get_known_rush_groups("rust_meetup_groups.csv")
224+
events_known_groups = get_20_events(get_known_rush_groups("rust_meetup_groups.csv"))
225+
return events_meetup_groups + events_known_groups
226+
227+
print(len(get_events()))

0 commit comments

Comments
 (0)