Created
November 4, 2012 18:29
-
-
Save rgaudin/4012893 to your computer and use it in GitHub Desktop.
This file contains 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 | |
import os | |
import sys | |
import tempfile | |
import datetime | |
os.environ['DJANGO_SETTINGS_MODULE'] = os.environ.get('DJANGO_SETTINGS_MODULE', | |
'settings') | |
from odk_viewer.pandas_mongo_bridge import NoRecordsFoundError, FlatCSVDataFrameBuilder | |
USERNAME = u'litreportcards' | |
ID_STRING = u'repeat_test' | |
# USERNAME = u'mberg' | |
# ID_STRING = u'hh_polio_survey' | |
USERNAME = u'reg' | |
# ID_STRING = u'test_repeat' | |
ID_STRING = u'test_repeat_multiples' | |
ID_STRING = u'test_double_repeat_multiples' | |
def launch(filename): | |
import envoy | |
envoy.run('/usr/bin/xdg-open %s' % filename) | |
# @profile | |
def export_csv(id_string=ID_STRING, username=USERNAME): | |
start = datetime.datetime.utcnow() | |
print('starting %s' % start) | |
query = None | |
# csv_dataframe_builder = FlatCSVDataFrameBuilder(username, id_string, query) | |
csv_dataframe_builder = FlatCSVDataFrameBuilder(username, id_string, query) | |
try: | |
fileh, filename = tempfile.mkstemp(suffix='.csv') | |
csv_dataframe_builder.export_to(filename) | |
os.close(fileh) | |
print(filename) | |
except NoRecordsFoundError: | |
print(u"No records found to export") | |
end = datetime.datetime.utcnow() | |
print('Ending %s, duration: %d minutes' % (end, (end - start).seconds/60)) | |
return filename | |
if __name__ == '__main__': | |
filename = export_csv(ID_STRING, USERNAME) | |
if len(sys.argv) > 1 and sys.argv[-1].lower() == 'launch': | |
launch(filename) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment