Skip to content

Instantly share code, notes, and snippets.


leah/ Secret

Created September 8, 2012 23:31
  • Star 3 You must be signed in to star a gist
  • Fork 6 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save leah/a1caaa73acb69a3807d9 to your computer and use it in GitHub Desktop.
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

what's with line 10?

Copy link

as noted by bilalhusain, line 10 does not do what leah intends for it to do. password may still be blank.

Copy link

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