|
74 | 74 | name |
75 | 75 | username |
76 | 76 | memberUrl |
77 | | - upcomingEvents { |
78 | | - count |
| 77 | + memberEvents(first: 10) { |
| 78 | + totalCount |
79 | 79 | pageInfo { |
80 | 80 | endCursor |
81 | 81 | } |
|
112 | 112 | urlname |
113 | 113 | city |
114 | 114 | link |
115 | | - upcomingEvents(input: { first: 1 }) { |
116 | | - count |
| 115 | + events(first: 10) { |
| 116 | + totalCount |
117 | 117 | pageInfo { |
118 | 118 | endCursor |
119 | 119 | } |
@@ -143,15 +143,21 @@ def send_request(token, query, vars) -> str: |
143 | 143 | """ |
144 | 144 | Request |
145 | 145 |
|
146 | | - POST https://api.meetup.com/gql |
| 146 | + POST https://api.meetup.com/gql-ext |
147 | 147 | """ |
148 | 148 |
|
149 | | - endpoint = 'https://api.meetup.com/gql' |
| 149 | + endpoint = 'https://api.meetup.com/gql-ext' |
150 | 150 |
|
151 | 151 | headers = {'Authorization': f'Bearer {token}', 'Content-Type': 'application/json; charset=utf-8'} |
152 | 152 |
|
153 | 153 | try: |
154 | | - r = requests.post(endpoint, json={'query': query, 'variables': vars}, headers=headers) |
| 154 | + # Parse vars string to JSON object if it's a string |
| 155 | + if isinstance(vars, str): |
| 156 | + variables = json.loads(vars) |
| 157 | + else: |
| 158 | + variables = vars |
| 159 | + |
| 160 | + r = requests.post(endpoint, json={'query': query, 'variables': variables}, headers=headers) |
155 | 161 | print(f"{Fore.GREEN}{info:<10}{Fore.RESET}Response HTTP Response Body: {r.status_code}") |
156 | 162 |
|
157 | 163 | # pretty prints json response content but skips sorting keys as it rearranges graphql response |
@@ -180,24 +186,36 @@ def format_response(response, location: str = "Oklahoma City", exclusions: str = |
180 | 186 |
|
181 | 187 | # TODO: add arg for `self` or `groupByUrlname` |
182 | 188 | # extract data from json |
183 | | - try: |
184 | | - data = response_json['data']['self']['upcomingEvents']['edges'] |
185 | | - if data[0]['node']['group']['city'] != location: |
186 | | - print(f"{Fore.YELLOW}{warning:<10}{Fore.RESET}Skipping event outside of {location}") |
187 | | - except KeyError: |
188 | | - if response_json['data']['groupByUrlname'] is None: |
189 | | - data = "" |
190 | | - print(f"{Fore.YELLOW}{warning:<10}{Fore.RESET}Skipping group due to empty response") |
191 | | - pass |
192 | | - else: |
193 | | - data = response_json['data']['groupByUrlname']['upcomingEvents']['edges'] |
194 | | - # TODO: handle no upcoming events to fallback on initial response |
195 | | - if response_json['data']['groupByUrlname']['city'] != location: |
196 | | - print(f"{Fore.RED}{error:<10}{Fore.RESET}No data for {location} found") |
197 | | - pass |
| 189 | + data = None |
| 190 | + |
| 191 | + # Check if response has expected structure |
| 192 | + if 'data' not in response_json: |
| 193 | + print( |
| 194 | + f"{Fore.RED}{error:<10}{Fore.RESET}GraphQL response missing 'data' key. Response: {json.dumps(response_json, indent=2)[:500]}" |
| 195 | + ) |
| 196 | + data = "" |
| 197 | + else: |
| 198 | + try: |
| 199 | + data = response_json['data']['self']['memberEvents']['edges'] |
| 200 | + if data and len(data) > 0 and data[0]['node']['group']['city'] != location: |
| 201 | + print(f"{Fore.YELLOW}{warning:<10}{Fore.RESET}Skipping event outside of {location}") |
| 202 | + except KeyError: |
| 203 | + try: |
| 204 | + if response_json['data'].get('groupByUrlname') is None: |
| 205 | + data = "" |
| 206 | + print(f"{Fore.YELLOW}{warning:<10}{Fore.RESET}Skipping group due to empty response") |
| 207 | + else: |
| 208 | + data = response_json['data']['groupByUrlname']['events']['edges'] |
| 209 | + # TODO: handle no upcoming events to fallback on initial response |
| 210 | + if response_json['data']['groupByUrlname']['city'] != location: |
| 211 | + print(f"{Fore.RED}{error:<10}{Fore.RESET}No data for {location} found") |
| 212 | + except KeyError as e: |
| 213 | + print(f"{Fore.RED}{error:<10}{Fore.RESET}KeyError accessing GraphQL data: {e}") |
| 214 | + print(f"{Fore.RED}{error:<10}{Fore.RESET}Response structure: {json.dumps(response_json, indent=2)[:500]}") |
| 215 | + data = "" |
198 | 216 |
|
199 | 217 | # append data to rows |
200 | | - if data is not None: |
| 218 | + if data: |
201 | 219 | for i in range(len(data)): |
202 | 220 | df.loc[i, 'name'] = data[i]['node']['group']['name'] |
203 | 221 | df.loc[i, 'date'] = data[i]['node']['dateTime'] |
|
0 commit comments