Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Dump all the previous events for a group. See
#!/usr/bin/env python3
import collections
import datetime
import pprint
import click
import jinja2
import requests
template = '''
<!DOCTYPE html>
<html lang="en">
<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;
<h1>Previous events for <a href="{{ 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 }}">{{ }}</a></td></tr>
{%- endfor %}</table>
{% endfor %}
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()
# Above is the equivalent of jQuery.extend()
# for Python 3.5: payload = {**default_payload, **offset_payload}
r = requests.get('', 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']:
offset = offset + 1
@click.option('--groupname', 'group_name', default='jornadahikers', help='Name of group in URL, i.e.<groupname>/')
@click.option('--apikey', 'api_key', envvar='MEETUP_API_KEY', help='Your API key, from')
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, [])
groupings[grouping_name] = grouping
print(generate_html(group_name, groupings))
if __name__ == '__main__':
buggsmoran commented May 22, 2016 edited

For those using Python on Windows. Windows does not like time formatted the way it is in line 84.
Anyone running the script in windows needs to change

date_pretty = time_obj.strftime('%a %b %-d')
date_pretty = time_obj.strftime('%b %d %Y')

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment