#!/usr/bin/env python # v0.31 , 9 May 2012 # Author: Brian Fiedler # front end to locust radar archive # adapted (rather easily) from my janim.py available at http://okazhun.com/fractals # students will be asked to improve on this import sys import cgi # to retrieve arguments from html forms import cgitb; cgitb.enable() # to display troubleshooting messages on the web page from datetime import datetime,timedelta # some user defined parameters: sopts=['national','southwest','south_Rockies','south_plains','south_missvly','southeast', 'cent_west','cent_Rockies','cent_plains','cent_missvly','mid_atlantic', 'northwest','north_Rockies','north_plains','upper_missvly','new_england'] ctlOnSide=True titlestring='locust radar archive' #maxdeltahr=48 #maximum time of animation maxdeltahr=96 #temporary for 2013 weather brieder #get the arguments from the form sent by user: form=cgi.FieldStorage() #this will have the arguments sent via the html form date=form.getvalue('thedate','2012032112') # 2012032112 is the default deltahr=form.getvalue('deltahr','24') # 24 hours is the default whichdata=form.getvalue('which','national') # national mosaic is the default try: #python 2.4.3 did not have strptime!! start=datetime.strptime(date,'%Y%m%d%H') except: # if strptime not availiable, do it with primitives: start=datetime( int(date[0:4]) , int(date[4:6]) , int(date[6:8]) , int(date[8:10]) ) deltahri=max(0,int(deltahr)) deltahri=min(deltahri,maxdeltahr) mn=60*int(deltahri) #deltahr placed within valid bounds and converted to minutes httpdir='http://locust.mmm.ucar.edu/imagearchive1/RadarComposites/'+whichdata+'/' urllist=[] #will be a list of all the urls of the images for i in range(0,mn+1,30): ahead=timedelta(minutes=i) #useful in the next wonderful statement thetime=start+ahead # this method jumps ahead over days months and years! ymd=thetime.strftime('%Y%m%d') hm=thetime.strftime('%H%M') url=httpdir+ymd+'/'+whichdata+'_'+ymd+hm+'.gif' #this is the complete path to the image file urllist.append(url) nim=len(urllist) #### some large template strings follow: top="""Content-type: text/html %s """ form="""
  0
""" ### use the paths to images stored in urllist list to make javascript links to the images: imagecode="""aniFrames[%d] = new Image();\naniFrames[%d].src = "%s";\n""" imagepaths='' for i in range(nim): imagepaths+=imagecode % (i,i,urllist[i]) # show first image in web page, before animation start replacing it: firstimgtag = 'your image should have been seen here!' % urllist[0] ### now put together the web page containing javascript for your animation: print top % (titlestring,nim-1) print imagepaths print script print '
' if ctlOnSide: #controls are on the left side of the image print "
" print form print "" print firstimgtag print "
" else: #controls are below the image print firstimgtag print form deltahr=str(mn/60) print """
""" print """ to hours ahead : (48 max)
download source code""" print '
'