Skip to content
Snippets Groups Projects

Add information on selecting quicklook data for download

Merged David Hoese requested to merge refactor-code-cleanup into develop
23 files
+ 3801
2066
Compare changes
  • Side-by-side
  • Inline
Files
23
+ 123
0
#!/var/www/wsgi/python-env/metobs/bin/python
"""List available EyeQ Camera images.
See `print_usage()` for more information
"""
import cgi
import cgitb; cgitb.enable()
import os
import sys
from datetime import datetime
from datetime import timedelta
from metobs import mytime
form = cgi.FieldStorage()
def get(name, default=None):
if form.has_key(name):
return form[name].value
return default
def print_usage():
print "ContentType: text/plain"
print
print """Provides image listings of SSEC RIG EyeQ Camera images.
Because the images may not be exactly spaced, being that processing may increase
the interval, images are listed by searching between the date provided and that
date plus the image resolution.
Parameters
==========
cam - (required) Camera name. West, East, etc ...
d - Date of image in CST (YYYY-MM-DD HH:MM:SS). Defaults to current time.
"""
#: resolution at which images are generated
image_rez = 10
#: timezone for image filename times
image_tz = mytime.OffsetTimezone(6)
hostname = 'tahiti.ssec.wisc.edu'
#: convert a file path to a server path`
url_for = lambda fpth: "http://"+hostname+fpth.replace("/beach", "/pub")
def image_path(cam, dt):
"""Get a path for an image on disk.
:param cam: Name of the camera
:param dt: datetime of the image file used to parse the name
"""
basedir = '/beach/incoming/Instrument_Data/METOBS/RIG/Cameras'
return os.path.join(basedir, cam + dt.strftime('/%Y/%m/%d/%H_%M_%S.trig+00.jpg'))
#
#
# You shouldn't need to change anything below here
#
#
def redirect_to(url):
print "Status: 302 Moved"
print "Location: " + url
print
def file_not_found():
print "Status: 404 File Not Found"
print
def headers(typ='plain'):
print "ContentType: text/" + typ
print
def main():
# required parameter
camera = get('cam')
if not camera:
print_usage()
return 1
# parse data from parameter, defaulting to current time in the
# timezone specified
date = get('d')
if not date:
date = mytime.utc_now()
date = mytime.set_tz(date, tz=image_tz)
else:
date = mytime.parse_stamp(date)
date = mytime.set_tz(date, tz=image_tz)
# images may not be exactly the same interval appart, therefore we have
# to attempt to locate the image
url = ""
pths = []
for i in range(image_rez):
fpth = image_path(camera, date + timedelta(seconds=i))
pths.append(fpth)
if os.path.exists(fpth):
url = url_for(fpth)
break
# successfully found an image
if url:
redirect_to(url)
if form.has_key('debug'):
headers()
for pth in pths:
print pth
return 1
# we should only get here if the file was not found
file_not_found()
return 1
sys.exit(main())
Loading