Skip to content

Instantly share code, notes, and snippets.


leah/ Secret

Created Sep 8, 2012
What would you like to do?
Grove Export
import json
import urllib2
import base64
def main():
# Auth info
username = raw_input('Username: ')
password = raw_input('Password: ')
if not username and password:
print 'Username and password required for export.'
base64string = base64.encodestring('%s:%s' % (username, password))[:-1]
# Helper to fetch from API
def get_resp(url):
req = urllib2.Request(url)
req.add_header("Authorization", "Basic %s" % base64string)
r = urllib2.urlopen(req)
raw =
resp = json.loads(raw)
return resp, raw
# Helper to get all messages for a channel
def get_messages(channel, until_id=None):
print '.'
url = '' % channel.get('id')
if until_id:
url = '%s?until_id=%s' % (url, until_id)
resp, raw = get_resp(url)
if not resp:
# Save messages to file
f = open('%s.json' % channel.get('name'), 'w')
# Moare messages!
until = resp[0].get('id')
print 'until_id:', until
get_messages(channel, until_id=until)
resp, raw = get_resp('')
orgs = resp.get('organizations')
print 'Found %s organization(s) to export.' % len(orgs)
for org in orgs:
print '\nExporting organization:', org.get('name')
resp, raw = get_resp('' % org.get('id'))
except urllib2.HTTPError, ex:
print 'Error: most likely this org has been suspended.'
channels = resp.get('channels')
print 'Found %s channel(s) to export.' % len(channels)
for channel in channels:
print 'Exporting channel:', channel.get('irc_name')
if __name__ == '__main__':
print 'Exporting Grove data.\n'
print '\nExport completed.'
Copy link

larsyencken commented Dec 6, 2012

Line 37 actually overwrites the dump on each pagination. It should use 'a' for append. Got a working fork here:

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