Skip to content

Commit 5869daa

Browse files
committed
Get Rush groups by fetching data from Meetup API
1 parent 13635dc commit 5869daa

File tree

1 file changed

+87
-1
lines changed

1 file changed

+87
-1
lines changed

tools/events-automation/generate_events_meetup.py

Lines changed: 87 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,90 @@ def authenticate():
2424
print("Failed to obtain access token")
2525
print("Status Code:", response.status_code)
2626
print("Response:", response.text)
27-
return None, None
27+
return None, None
28+
29+
def fetch_groups(endCursor=""):
30+
URL = "https://api.meetup.com/gql"
31+
access_token, refresh_token = authenticate()
32+
33+
if not access_token:
34+
print("Authentication failed, cannot proceed to fetch events.")
35+
return
36+
37+
headers = {
38+
"Authorization": f"Bearer {access_token}",
39+
"Content-Type": "application/json",
40+
}
41+
42+
data = {
43+
"query": """
44+
query (
45+
$searchGroupInput: ConnectionInput!,
46+
$searchGroupFilter: SearchConnectionFilter!,
47+
$sortOrder: KeywordSort!
48+
) {
49+
keywordSearch(
50+
input: $searchGroupInput,
51+
filter: $searchGroupFilter,
52+
sort: $sortOrder
53+
) {
54+
pageInfo {
55+
hasNextPage
56+
endCursor
57+
}
58+
edges {
59+
node {
60+
result {
61+
... on Group {
62+
id
63+
name
64+
link
65+
urlname
66+
latitude
67+
longitude
68+
}
69+
}
70+
}
71+
}
72+
}
73+
}
74+
""",
75+
"variables": {
76+
"searchGroupFilter": {
77+
"query": "Rust",
78+
"lat": 0.0,
79+
"lon": 0.0,
80+
"radius": 20000,
81+
"source": "GROUPS"
82+
},
83+
"searchGroupInput": {
84+
"first": 200,
85+
"after": endCursor
86+
},
87+
"sortOrder":{
88+
"sortField": "RELEVANCE"
89+
}
90+
}
91+
}
92+
return requests.post(url=URL, headers=headers, json=data)
93+
94+
def get_rush_groups():
95+
"""
96+
Return a dictionary of groups
97+
"""
98+
endCursor = None
99+
groups = dict()
100+
while True:
101+
response = fetch_groups(endCursor).json()
102+
data = response['data']
103+
edges = data['keywordSearch']['edges']
104+
pageInfo = data['keywordSearch']['pageInfo']
105+
for node in edges:
106+
group = node["node"]["result"]
107+
if not (group["id"] in groups):
108+
groups[group["id"]] = group
109+
if pageInfo['hasNextPage']:
110+
endCursor = pageInfo['endCursor']
111+
else:
112+
break
113+
return groups

0 commit comments

Comments
 (0)