Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
meetup.com api
#!/usr/bin/python
import datetime
from datetime import date
import urllib2
import json
import time
import re
# Magic
import sys # sys.setdefaultencoding is cancelled by site.py
reload(sys) # to re-enable sys.setdefaultencoding()
sys.setdefaultencoding('utf-8')
print "Rounding up the ponies ..."
key = "3a7711454d145e404e531c2ee6f391d"
url = "https://api.meetup.com/2/open_events?&sign=true&photo-host=public&state=ky&city=lexington&country=usa&text=openstack&radius=10000&sign=true&key=" + key
week = 7
twoweek = 14
now = datetime.datetime.now()
nowts = time.mktime(now.timetuple())
print "Fetching meetups ..."
response = urllib2.urlopen(url)
m = response.read()
print "Parsing results ..."
r = json.loads(m)
meetups = r['results']
groups = {}
print "Fetching group details ..."
for meetup in meetups:
groups[ str( meetup['group']['id'] ) ] = meetup['group']['name']
keys = groups.keys()
keyarg = ",".join( keys )
group_url = "https://api.meetup.com/2/groups?&sign=true&photo-host=public&group_id=" + keyarg + "&key=" + key
response = urllib2.urlopen( group_url )
m = response.read()
r = json.loads(m)
grps = r['results']
grp_deets = {}
for g in grps:
grp_deets[ g['id'] ] = g
print "Ok, ready to print meetup details ..."
weeklater = (nowts * 1000 ) + ( week * 86400 * 1000 )
twoweeklater = (nowts * 1000 ) + ( twoweek * 86400 * 1000 )
tweets = open('meetups.tweets', 'w')
mlist = open('meetups.mlist', 'w')
wiki = open('meetups.wiki', 'w')
# Standard intro to mailing list post
mlist.write( '''The following are the meetups I'm aware of in the coming week where
OpenStack and/or RDO enthusiasts are likely to be present. If you know
of others, please let me know, and/or add them to
http://rdoproject.org/Events
If there's a meetup in your area, please consider attending. If you
attend, please consider taking a few photos, and possibly even writing
up a brief summary of what was covered.
--Rich
''')
for meetup in meetups:
eventts = int( meetup['time'] + meetup['utc_offset'] )
# Skip it if it's more than two weeks away
if eventts > twoweeklater:
continue
eventtime = date.fromtimestamp( eventts/1000 )
t = eventtime.strftime("%c");
# Don't care about the time
t = re.sub( ' \d\d:\d\d:\d\d \d\d\d\d', '', t );
# Group information ...
grp = grp_deets[ meetup['group']['id'] ]
# For the wiki ...
eventout = "* " + t + ' [' + meetup['event_url'] + ' ' + meetup['name'] + "], " + grp['city'] + ', '
if 'state' in grp.keys():
eventout = eventout + grp['state'] + ', '
eventout = eventout + grp['country'] + "\n"
wiki.write( str(eventout) )
# For everything else, a week is enough
if eventts > weeklater:
continue
# For Twitter
eventout = t + ' in ' + grp['city'] + ', '
if 'state' in grp.keys():
eventout = eventout + grp['state'] + ', '
eventout = eventout + grp['country'] + ': ' + meetup['name'] + ' - ' + meetup['event_url'] + " #OpenStack #Meetup\n"
tweets.write( str( eventout ))
# For mailing list
eventout = '* ' + t + ' in ' + grp['city'] + ', '
if 'state' in grp.keys():
eventout = eventout + grp['state'] + ', '
eventout = eventout + grp['country'] + ': ' + meetup['name'] + ' - ' + meetup['event_url'] + "\n\n"
mlist.write( str( eventout ))
# Barn door
tweets.close()
mlist.close()
wiki.close()
print "Done!\n"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.