Skip to content
This repository has been archived by the owner on Jan 25, 2024. It is now read-only.

Commit

Permalink
Update meetup functions to use field_event_api_key for url generation
Browse files Browse the repository at this point in the history
  • Loading branch information
bcsnipes committed Sep 14, 2019
1 parent cddb7c3 commit 5505f43
Showing 1 changed file with 6 additions and 13 deletions.
19 changes: 6 additions & 13 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,13 @@ def get_group_lists():

# Takes list of groups and makes API call to Meetup.com to get event details. Returns list.
def get_meetup_events(group_list):
# Extract https:www.meetup.com/'groupName' from each item in group_list
group_urls = [i['field_event_calendar_homepage'] for i in group_list]
# Extract field_event_api_key from each item in group_list
group_apis = [i['field_events_api_key'] for i in group_list]
# Create empty list to be returned by the function
all_events = []
for url in group_urls:
url = url.replace('www', 'api')
# Urls are currently written as: https:www.meetup.com/'groupname', but random urls return as https:www.meetup.com/'groupname'/events.
# To avoid 404 errors, we need to strip the trailing 'events/', if it exists, before appending the api request url
if url.endswith('events/'):
url = url.rstrip('/')
url += "?&sign=true&photo-host=public&page=20"
else:
url += "events?&sign=true&photo-host=public&page=20"
for api in group_apis:
# Create url from group name found in Organization API's field_event_api_key
url = 'https://api.meetup.com/{}/events?&sign=true&photo-host=public&page=20'.format(api)
r = requests.get(url)
if r.status_code != 200:
raise Exception('Could not connect to Meetup API at {}. Status Code: {}'.format(url, r.status_code))
Expand All @@ -66,9 +60,8 @@ def get_meetup_events(group_list):
def format_meetup_events(events_raw, group_list):
events = []
for event in events_raw:

venue_dict = event.get('venue')
group_item = [i for i in group_list if i.get('field_events_api_key') == str(event['group']['id'])][0]
group_item = [i for i in group_list if i.get('field_events_api_key') == str(event['group']['urlname'])][0]
tags = group_item.get('field_org_tags')
uuid = group_item.get('uuid')
nid = group_item.get('nid')
Expand Down

0 comments on commit 5505f43

Please sign in to comment.