@@ -0,0 +1,1626 @@
+#!/usr/bin/env python2%0A# -- coding: utf-8 --%0A%0Aimport requests%0Aimport unicodecsv%0Afrom utils import get_api_key%0A%0Atoken = get_api_key()%0Aurl = 'https://www.muckrock.com/api_v1/'%0A%0Aheaders = %7B'Authorization': 'Token %25s' %25 token, 'content-type': 'application/json'%7D%0A%0A%0AassignmentID = raw_input('What assignment are you trying to export? Look at the numbers at the end of the URL:  ')%0Anext_ = url + %22assignment-responses/?crowdsource=%22 + str(assignmentID)%0A%0Abasic_fields = %5B%0A%22id%22,%0A%22user%22,%0A%22datetime%22,%0A%22tags%22,%0A%22skip%22,%0A%22number%22,%0A%22flag%22,%0A%22gallery%22,%0A%22crowdsource%22%0A%5D%0A%0Aassignment_fields = %5B%5D%0A%0Apage = 1%0A%0Acsv_file = open('assignment ' + str(assignmentID) +  ' export.csv', 'w')%0Acsv_file.seek(0)%0Acsv_writer = unicodecsv.writer(csv_file)%0A%0A%0Ar = requests.get(next_, headers=headers)%0Ajson = r.json()%0A%0Afor column in json%5B'results'%5D%5B0%5D%5B'values'%5D:%0A    assignment_fields.append(column%5B'field'%5D)%0Acsv_writer.writerow(basic_fields + assignment_fields)%0A%0Awhile next_ is not None:%0A    r = requests.get(next_, headers=headers)%0A    try:%0A        json = r.json()%0A        next_ = json%5B'next'%5D%0A        for datum in json%5B'results'%5D:%0A            submissions = %5B%5D%0A            for field in basic_fields:%0A                submissions.append(datum%5Bfield%5D)%0A            for entry in datum%5B%22values%22%5D:%0A                submissions.append(entry%5B%22value%22%5D)%0A            csv_writer.writerow(submissions)%0A#            csv_writer.writerow(datum%5Bfield%5D for field in basic_fields + )%0A            # + datum%5B'values'%5D%5Bassignment_fields%5D for field in assignment_fields%0A        print 'Page %25d of %25d' %25 (page, json%5B'count'%5D / 40)%0A        page += 1%0A    except Exception as e:%0A        print e%0A

Create export_assignment_responses.py