Skip to content

Instantly share code, notes, and snippets.

@jaytaylor
Forked from gjlondon/asana_dump.py
Last active August 29, 2015 14:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jaytaylor/c96dc7bc4122f35531eb to your computer and use it in GitHub Desktop.
Save jaytaylor/c96dc7bc4122f35531eb to your computer and use it in GitHub Desktop.
Use Asana's "export project to JSON" function and copy-paste contents to an "X.json" file. *Note* Requires external library: "unicdecode", available from https://pypi.python.org/pypi/Unidecode
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""Use Asana's "export project to JSON" function and copy-paste contents to an "X.json" file."""
import codecs
import csv
import json
import pprint
import re
import sys
import unidecode
def main():
if len(sys.argv) < 2:
sys.stderr.write('error: missing required parameter: input filename\n')
return 1
inputFile = sys.argv[1]
if not inputFile.endswith('.json'):
sys.stderr.write('error: only JSON input files are accepted\n')
return 1
outputFile = re.sub(r'''^(.*)\.json''', r'''\1.csv''', inputFile)
assert outputFile != inputFile, 'the input filename must not be the same as the generated output filename'
pp = pprint.PrettyPrinter(indent=4)
with codecs.open(inputFile, encoding='utf-8', mode='rb') as fh:
inputData = json.loads(fh.read())
with open(outputFile, 'wb') as fh:
csvWriter = csv.writer(fh, delimiter=',')
outputData = []
for task in inputData['data']:
name = unidecode.unidecode(task['name'])
# Choose conditions for inclusion and what fields you want to include in dump.
if not task['completed']:
outputData.append([name, task['created_at'], task['modified_at'], task['tags']])
csvWriter.writerows(outputData)
return 0
if __name__ == '__main__':
sys.exit(main())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment