Part One - APIs - Retrieve Data From Meetup


In [ ]:
# Import everything we'll need
import json
import csv
import urllib2

In [ ]:
# First we'll get a list of categories

# Your meetup API key. This will be used for all requests.
api_key = ''

# The base path for calling the api
base_path = "https://api.meetup.com"

# Meetup category path - returns a list of all the categories
category_path = '/2/categories'

# Build the full url to call
url_to_call = base_path + category_path + '?&sign=true&key=' + api_key

# Check to be sure we have the right one
print(url_to_call)

In [ ]:
# Load the JSON response as a python dict
category_list = json.load(urllib2.urlopen(url_to_call))

# Loop through the results and print them out
for result in category_list['results']:
    print(result)

In [ ]:
# Save the categories to a CSV file
with open('meetup_categories.csv', 'wb') as csvfile:
    writer = csv.writer(csvfile, delimiter=',', quotechar='"', quoting=csv.QUOTE_ALL)
    writer.writerow(['id', 'shortname', 'name'])
    for result in category_list['results']:
        writer.writerow([result['id'], 
                         result['shortname'],
                         result['name']])

                         # So we know that the CSV file was indeed created
print("CSV creation complete")

In [ ]:
# Retrieve the members of a Meetup group

meetup_members_path = '/2/members'
group_url = 'data-wranglers-dc'
user_url_to_call = base_path + meetup_members_path + '?&sign=true&key=' + api_key + '&group_urlname=' + group_url

print(user_url_to_call)

In [ ]:
# Load the JSON response as a python dict
dwdc_member_list = json.load(urllib2.urlopen(user_url_to_call))

# Loop through the results and print them out
for result in dwdc_member_list['results']:
    print(result)

In [ ]: