Created
July 28, 2011 18:46
-
-
Save gadamc/1112229 to your computer and use it in GitHub Desktop.
podio_bigdump
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
from pypodio2 import api | |
import sys, shutil, os, json | |
c = api.OAuthClient(sys.argv[1],sys.argv[2], sys.argv[3], sys.argv[4]) | |
orginfo = c.transport.get(url = '/org/') | |
def writerawtext(filename, data): | |
try: | |
f = open(filename, 'w') | |
f.write(data.encode('utf-8')) | |
f.close() | |
except: pass | |
def writetext(filename, data): | |
writerawtext(filename, json.dumps(data, indent=1)) | |
def writedata(filename, data): | |
try: | |
f = open(filename, 'wb') | |
f.write(data) | |
f.close() | |
except: pass | |
for org in orginfo: | |
try: os.mkdir(org['name']) | |
except: pass | |
writetext(os.path.join(org['name'],org['name']+'_organization_info.json'), org) | |
for space in org['spaces']: | |
spaceDir = os.path.join(org['name'], space['name']) | |
try: os.mkdir(spaceDir) | |
except: pass | |
print 'processing space', space['name'] | |
spaceinfo = c.transport.get(url = '/space/%s' % space['space_id']) | |
writetext(os.path.join(spaceDir,space['name']+'_space_info.json'),spaceinfo) | |
appslist = c.Application.list_in_space(space['space_id']) | |
appsDir = os.path.join(spaceDir, 'Apps') | |
try: os.mkdir( appsDir ) | |
except: pass | |
for app in appslist: | |
thisAppDir = os.path.join( appsDir, app['config']['name']) | |
try: os.mkdir(thisAppDir) | |
except: pass | |
print ' app', app['config']['name'] | |
appinfo = c.transport.get(url = '/app/%s' % app['app_id']) | |
writetext(os.path.join(thisAppDir, 'app_info.json'), appinfo) | |
itemsinapp = c.transport.get(url = '/item/app/%s/' % app['app_id']) | |
itemsDir = os.path.join(thisAppDir, 'items') | |
try: os.mkdir(itemsDir) | |
except: pass | |
for item in itemsinapp['items']: | |
itemDir = os.path.join(itemsDir, item['title']) | |
try: os.mkdir(itemDir) | |
except: pass | |
print ' item', item['title'] | |
iteminfo = c.transport.get(url = '/item/%s' % item['item_id']) | |
writetext(os.path.join(itemDir, 'item_info.json'), iteminfo) | |
for fileinfo in iteminfo['files']: | |
if fileinfo['link'].split('://')[1].startswith('files'): #makes sure its not in the 'downloads.podio.com' URL. Podio plans to fix this so all files are in 'files' | |
thehandler = lambda resp, data: (resp, data) | |
response, rawdata = c.transport.get(url = '/file/%s/raw' % fileinfo['file_id'], handler = thehandler) | |
writedata(os.path.join(itemDir, fileinfo['name']), rawdata) | |
comments = c.transport.get(url = '/comment/item/%s' % item['item_id']) | |
for i in range(len(comments)): | |
comment = comments[i] | |
writerawtext(os.path.join(itemDir, 'comment_%d.txt' % i), comment['value']) | |
writerawtext(os.path.join(itemDir, 'comment_%d.rtf' % i), comment['rich_value']) | |
writetext(os.path.join(itemDir, 'comment_%d.json' % i), comment) | |
if len(comment['files']) > 0: | |
commentDir = os.path.join(itemDir, 'comment_files_%d' % i) | |
try: os.mkdir(commentDir) | |
except: pass | |
for file in comment['files']: | |
if file['link'].split('://')[1].startswith('files'): #makes sure its not in the 'downloads.podio.com' URL. P\odio plans to fix this so all files are in 'files' | |
thehandler = lambda resp, data: (resp, data) | |
response, rawdata = c.transport.get(url = '/file/%s/raw' % file['file_id'], handler = thehandler) | |
writedata(os.path.join(commentDir, file['name']), rawdata) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment