If you’re an organizer on Meetup.com, it’s a pain to look for events that have happened in the past in your group. Meetup doesn’t have a way to search only within your group, and paging through the calendar is a pain if your group is old or if you have a lot of events.
I’ve written a quick Python script that uses Meetup.com’s API to get all of a Meetup group’s meetup events and generate an easy-to-search and view report. For the Jornada Hiking & Outdoors Club , you can see a report of all our previous events .
The script is on Github as a gist if you’d to run it against your own Meetup.com groups. You’ll need to know the group’s “custom address” (which is also in the URL for your group) and have an Meetup.com API key .
#!/usr/bin/env python3
import collections
import datetime
import pprint
import click
import jinja2
import requests
template = '''
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name=viewport content="width=device-width, initial-scale=1.0">
<style type="text/css">
td.date_pretty {
text-align: right;
}
</style>
</head>
<body>
<h1>Previous events for <a href="http://www.meetup.com/{{ group_name }}/">{{ group_name }}</a>
{% for grouping_name, events in groupings.items() %}
<h2>{{ grouping_name }}</h2>
<table>{% for i in events %}
<tr><td class="date_pretty">{{ i.date_pretty }}</td><td><a href="{{ i.event_url }}">{{ i.name }}</a></td></tr>
{%- endfor %}</table>
{% endfor %}
</body>
</html>
'''
default_payload = { 'status': 'past' }
def generate_html(group_name, g):
global template
je = jinja2.Environment()
jt = je.from_string(template)
out = jt.render(group_name=group_name, groupings=g)
return out
def generate_events(group_name, api_key):
offset = 0
while True:
offset_payload = { 'offset': offset,
'key': api_key,
'group_urlname': group_name }
payload = default_payload.copy()
payload.update(offset_payload)
# Above is the equivalent of jQuery.extend()
# for Python 3.5: payload = {**default_payload, **offset_payload}
r = requests.get('https://api.meetup.com/2/events', params=payload)
json = r.json()
results, meta = json['results'], json['meta']
for item in results:
yield item
# if we no longer have more results pages, stop…
if not meta['next']:
return
offset = offset + 1
@click.command()
@click.option('--groupname', 'group_name', default='jornadahikers', help='Name of group in Meetup.com URL , i.e. http://meetup.com/<groupname>/')
@click.option('--apikey', 'api_key', envvar='MEETUP_API_KEY', help='Your Meetup.com API key, from https://secure.meetup.com/meetup_api/key/')
def go(group_name, api_key):
all_events = list(generate_events(group_name, api_key))
for event in all_events:
# convert time returned by Meetup API
time = int(event['time'])/1000
time_obj = datetime.datetime.fromtimestamp(time)
# create a pretty-looking date, and group by month
date_pretty = time_obj.strftime('%a %b %-d')
grouping_name = time_obj.strftime('%b %Y')
event['grouping_name'] = grouping_name
event['date_pretty'] = date_pretty
# group by month
groupings = collections.OrderedDict()
for event in all_events:
grouping_name = event['grouping_name']
grouping = groupings.get(grouping_name, [])
grouping.append(event)
groupings[grouping_name] = grouping
print(generate_html(group_name, groupings))
if __name__ == '__main__':
go()
After installing the dependencies (Python 3.4+, click, jinja2, and requests), usage is pretty easy:
Usage: Meetup-past-events.py [OPTIONS ]
Options: If you’ve found this blog post, downloading and running the script might be too much for you. Feel free to contact me with a link to your group and I’ll e-mail a list for your group.
Comments
Comments powered by Disqus