leah / export.py secret
Created

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist

Grove Export

View export.py
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
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.'
return
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 = r.read()
resp = json.loads(raw)
r.close()
return resp, raw
# Helper to get all messages for a channel
def get_messages(channel, until_id=None):
print '.'
url = 'https://grove.io/api/channels/%s/messages' % channel.get('id')
if until_id:
url = '%s?until_id=%s' % (url, until_id)
 
resp, raw = get_resp(url)
if not resp:
return
# Save messages to file
f = open('%s.json' % channel.get('name'), 'w')
f.write(raw)
f.close()
# Moare messages!
until = resp[0].get('id')
print 'until_id:', until
get_messages(channel, until_id=until)
 
resp, raw = get_resp('https://grove.io/api/auth')
orgs = resp.get('organizations')
print 'Found %s organization(s) to export.' % len(orgs)
for org in orgs:
print '\nExporting organization:', org.get('name')
try:
resp, raw = get_resp('https://grove.io/api/organizations/%s' % org.get('id'))
except urllib2.HTTPError, ex:
print 'Error: most likely this org has been suspended.'
continue
channels = resp.get('channels')
print 'Found %s channel(s) to export.' % len(channels)
for channel in channels:
print 'Exporting channel:', channel.get('irc_name')
get_messages(channel)
 
if __name__ == '__main__':
print 'Exporting Grove data.\n'
main()
print '\nExport completed.'

what's with line 10?

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

Line 37 actually overwrites the dump on each pagination. It should use 'a' for append. Got a working fork here: https://gist.github.com/d3eb3c06d6eb0c741684

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.