Skip to content

Interactive interface for browsing global, full-resolution satellite imagery

Documentation for echo.cgi

Mike McGann899d5863e58c
diff --git a/src/data/echo.cgi b/src/data/echo.cgi
index e79c9a197..34c0da60f 100755
--- a/src/data/echo.cgi
+++ b/src/data/echo.cgi
@@ -19,56 +19,132 @@ import shutil
import sys
from urllib2 import Request, urlopen, HTTPError
-endpoint = "https://api.echo.nasa.gov/catalog-rest/echo_catalog/granules/search.json?page_size=300"
+endpoint = "https://api.echo.nasa.gov/catalog-rest/echo_catalog/" \
+ "granules/search.json?page_size=300"
class RequestError(Exception):
- pass
-
-
-class ServiceError(Exception):
+ """
+ Exception raised when a missing or an invalid parameter is provided
+ """
pass
def handle_error(error_code, message, options, info=None):
- print "Content-type: text/html"
- print "Status: %s" % error_code
- print ""
- print "<h2>%s Error</h2>" % error_code
- print message
- if options.error and message:
- print "<br/><br/>"
- print str(info)
- sys.exit(1)
+ """
+ Displays an error page to the client and exits the program with a return
+ code of one.
+
+ Parameters:
+ - error_code: HTTP status code to set in the header
+ - message: Message reported to the user
+ - options: Execution options
+ - info: Additional information to display to the user if options.error
+ is True
+ """
+ print "Content-type: text/html"
+ print "Status: %s" % error_code
+ print ""
+ print "<h2>%s Error</h2>" % error_code
+ print message
+ if options.error and info:
+ print "<br/><br/>"
+ print str(info)
+
+ # Print to standard out for the Apache error log
+ sys.stderr.write("worldview/echo.cgi [%s]: %s" % (error_code, message))
+ if info:
+ sys.stderr.write(": %s" % info)
+ sys.stderr.write("\n")
+
+ sys.exit(1)
def bad_request(options, info=None):
+ """
+ Displays the error page with a 400 error and a Bad Request message. Exits
+ the program with a return code of one.
+
+ Parameters:
+ - options: Execution options
+ - info: Additional information to display to the user if options.error
+ is True
+ """
handle_error(400, "Bad request", options, info)
def internal_server_error(options, info=None):
+ """
+ Displays the error page with a 500 error and a Unexpected Error message.
+ Exits the program with a return code of one.
+
+ Parameters:
+ - options: Execution options
+ - info: Additional information to display to the user if options.error
+ is True
+ """
handle_error(500, "Unexpected error", options, info)
def service_unavailable(options, info=None):
+ """
+ Displays the error page with a 503 error and a Service Unavailable message.
+ Exits the program with a return code of one.
+
+ Parameters:
+ - options: Execution options
+ - info: Additional information to display to the user if options.error
+ is True
+ """
handle_error(503, "Service Unavailable", options, info)
def aql_list(fields):
+ """
+ Creates an AQL list from a list of CGI fields.
+
+ Parameters:
+ - fields: List of CGI fields
+
+ Returns:
+ - List of XML string fragments containing list and value elements.
+ """
result = ["<list>"]
for field in fields:
result += ["<value>%s</value>" % field]
result += ["</list>"]
return result
+
def aql_date(t):
+ """
+ Creates an AQL Date element from a datetime object.
+
+ Parameters:
+ - t: datetime object to convert
+
+ Returns:
+ - XML string fragment containing a Date element.
+ """
return "<Date YYYY='%s' MM='%s' DD='%s' HH='%s' MI='%s' SS='%s'/>" % (
t.year, t.month, t.day, t.hour, t.minute, t.second
)
def create_xml(fields):
+ """
+ Creates an XML document given the provided CGI fields
+
+ Parameters:
+ - fields: CGI fields to use a parameters for the ECHO query
+
+ Returns:
+ - AQL XML document for the ECHO query request as a string.
+ """
+
+ # It isn't necessary to have the official prolog and DOCTYPE
xml = ["<?xml version='1.0' encoding='UTF-8' ?>"]
- xml = ['<!DOCTYPE query PUBLIC "-//ECHO CatalogService (v10)//EN" "http://api.echo.nasa.gov/echo/dtd/IIMSAQLQueryLanguage.dtd">']
+ xml = ['<!DOCTYPE query PUBLIC "-//ECHO CatalogService (v10)//EN" '
+ '"http://api.echo.nasa.gov/echo/dtd/IIMSAQLQueryLanguage.dtd">']
xml += ["<query>", "<for value='granules'/>"]
@@ -102,6 +178,14 @@ def create_xml(fields):
def query_echo(options, xml):
+ """
+ Submit an AQL document to ECHO and proxy the results to standard out.
+
+ Parameters:
+ - options: Execution options.
+ - xml: AQL document to submit to ECHO
+ """
+
url = endpoint
headers = {
"Content-type": "application/xml"
@@ -115,12 +199,29 @@ def query_echo(options, xml):
def process_request(options):
+ """
+ Handle the request by converting CGI parameters into an AQL document
+ and sumbitting to ECHO.
+
+ CGI Parameters:
+ - day: UTC day to search for in YYYY-DD-MM format
+ - shortName: Product short name, may be used multiple times
+ - dataCenterId: Data center that provides the data, may be used multiple
+ times. Note this field is required to decrease query times due to
+ data center specific ACLs.
+
+ Parameters:
+ - options: Execution options
+ """
fields = cgi.FieldStorage()
+
+ if len(fields) == 0:
+ raise RequestError("No parameters")
required_fields = ["day", "shortName", "dataCenterId"]
for required_field in required_fields:
if required_field not in fields:
- bad_request(options, "Missing parameter: %s" % required_field)
+ raise RequestError("Missing parameter: %s" % required_field)
xml = create_xml(fields)
@@ -132,6 +233,12 @@ def process_request(options):
def parse_options():
+ """
+ Allow command line arguments for easy debugging at the command line.
+
+ Returns:
+ Execution options
+ """
parser = OptionParser()
parser.add_option("-a", "--all", action="store_true",
help="Print all debugging information")
@@ -149,7 +256,11 @@ def parse_options():
return options
+
if __name__ == '__main__':
+ """
+ Entry point
+ """
options = parse_options()
try:
process_request(options)
diff --git a/src/js/Worldview/Widget/DataDownload.js b/src/js/Worldview/Widget/DataDownload.js
index c75a66eff..d741dc19d 100644
--- a/src/js/Worldview/Widget/DataDownload.js
+++ b/src/js/Worldview/Widget/DataDownload.js
@@ -34,7 +34,8 @@ Worldview.Widget.DataDownload = function(model, config, spec) {
var HTML_WIDGET_ACTIVE = "<img src='images/cameraon.png'></img>";
var preloader = Worldview.Preloader([
- "images/activity.gif"
+ "images/activity.gif",
+ "images/cameraon.png"
]);
var init = function() {