Skip to main content
All CollectionsAPI and Developer DocumentationHighly customized reports with Python
Export data to a TXT file using python and the advanced reporting engine
Export data to a TXT file using python and the advanced reporting engine

Generate a completely customized TXT output from a report

Zack Schwartz avatar
Written by Zack Schwartz
Updated over 3 months ago

The following article is for advanced usage only is applicable if you want to generate a raw TXT file of your submission data.

A prerequisite for this article assumes that you know how to create a basic report in OpenWater.

There are two ways to creating a TXT report.

  • Render from Plain Text

  • Render from Python Script

To get started with a TXT export, first navigate to your report and click on Advanced and then check the box for Enable TXT Export. Then click Manage.

Render from Plain Text

Render from Plain Text will simply output the TXT in the format you have written. Click Insert Variable to design your output. See example below.

{ExternalUserAuthData} is a great variable for seeing the data that was passed in through single single on if that is applicable to you.

Click Save and tab over to General. Refresh your page and you should now see TXT as an option.

Render from Python Script

This is a more advanced option that requires python code. You would go with this option if a straight rendering from plain text is insufficient in designing the type of output you are looking for.

The TXT that is rendered as output for the report is actually completely defined by you via a python script. The boilerplate below can be used as the most basic Python report.

#HEADER#
data = []
#END HEADER#

#BODY#
temp = {}
temp["Id"] = {ApplicationCode}
temp["Email"] = {Email}
temp["Category"] = {ApplicationCategoryName}
temp["Title"] = {ApplicationName}
temp["Date"] = {SubmittedAt}
temp["WinnerInfo"] = {ApplicationWinningTypes}
data.append(temp)
#END BODY#

#FOOTER#
all_entries = []
all_entries = sorted(data, key=lambda x: x['Id'])
for item in all_entries:
    print item["Id"]
    print "\n"
    print item["Email"]
    print "\n"
    print item["Category"]
    print "\n"
    print item["Title"]
    print "\n"
    print item["Date"]
    print "\n"
    print item["WinnerInfo"]
    print "\n\n"
#END FOOTER# 

The #HEADER# section is a good place to define variables that will be stored once. The #BODY# section is rendered once for every submission included in the report. This is where you would want to make use of the variables. And finally #FOOTER# is also rendered once.

The print statements will render that line out to the TXT output.

Click Save and Run Test which will choose up to 10 submissions to render and output the JSON file. If there are any syntax errors, it will tell you. You can also click Save and Export Script which will generate the resulting Python script for you to analyze for any other debugging purposes.

Run the Report

To run the report in full, return to the General and tab and refresh your page to see TXT as an option now.

Did this answer your question?