Package noaadata :: Module waterlevelraw
[hide private]
[frames] | no frames]

Source Code for Module noaadata.waterlevelraw

  1  #!/usr/bin/env python 
  2  __version__ = '$Revision: 4762 $'.split()[1] 
  3  __date__ = '$Date: 2006-09-19 14:56:22 -0400 (Tue, 19 Sep 2006) $'.split()[1] 
  4  __author__ = 'Kurt Schwehr' 
  5   
  6  __doc__=''' 
  7  Handling code for noaa tide station data.  
  8   
  9  The Web Services Description Language (WSDL) definition for the 
 10  query/response from the NOAA Axis server. 
 11   
 12   
 13  U{<kurt@ccom.unh.edu>} 
 14   
 15  @see: U{NOAA Axis page<http://opendap.co-ops.nos.noaa.gov/axis/>} 
 16  @see: U{WSDL<http://opendap.co-ops.nos.noaa.gov/axis/services/WaterLevelRawSixMin?wsdl>} 
 17  @see: U{SOAP XML request<http://opendap.co-ops.nos.noaa.gov/axis/webservices/activestations/samples/request.xml>} 
 18  @see: U{SOAP XML response<http://opendap.co-ops.nos.noaa.gov/axis/webservices/activestations/samples/response.xml>} 
 19  @see: U{Java SOAP code<http://opendap.co-ops.nos.noaa.gov/axis/webservices/activestations/samples/client.html>} 
 20  @see: U{Web interface<http://opendap.co-ops.nos.noaa.gov/axis/webservices/activestations/index.jsp>} 
 21  @see: U{XPathTutorial<http://www.zvon.org/xxl/XPathTutorial/General/examples.html>} 
 22  @see: U{python lxml<http://codespeak.net/lxml/>} 
 23   
 24  @author: '''+__author__+''' 
 25  @version: ''' + __version__ +''' 
 26  @copyright: 2006 
 27  @var __date__: Date of last svn commit 
 28  @undocumented: __version__ __author__ __doc__ myparser success  
 29   
 30  ''' 
 31   
 32  import sys, httplib 
 33   
 34  # FIX: document the datums 
 35  datumList = ['MLLW','MSL','MHW','STND','IGLD','NGVD','NAVD'] 
 36  unitList = ['Meters','Feet'] 
 37   
 38  import datetime 
 39   
40 -def getWaterLevelSoappyNow(stationId,debug=False):
41 ''' 42 Use OLD SOAPpy interface to get the waterlevel for a station 43 ''' 44 45 d = datetime.datetime.utcnow() 46 47 print 'FIX: do this in seconds space!!!! This is crap!' 48 49 startD = d + datetime.timedelta(minutes=-20) 50 endD = d + datetime.timedelta(minutes=10) 51 #startMin = int(d.minute) - 6 52 #endMin = int(d.minute) + 1 53 print startD,endD,d 54 55 beginDate = str(startD.year)+('%02d' % startD.month)+('%02d' % startD.day)+' '+ ('%02d' % (startD.hour))+':'+('%02d' % (startD.minute)) 56 endDate = str(endD.year)+('%02d' % endD.month)+('%02d' % endD.day)+' '+ ('%02d' % (endD.hour))+':'+('%02d' % (endD.minute)) 57 #print beginDate,endDate 58 59 from SOAPpy import SOAPProxy 60 url = 'http://opendap.co-ops.nos.noaa.gov/axis/services/WaterLevelRawSixMin' 61 namespace='urn:WaterLevelRawSixMin' # This really can be anything. It is ignored 62 server = SOAPProxy(url,namespace) 63 if debug: server.config.debug=1 64 #response = server.getWaterLevelRawSixMin(stationId=str(stationId),beginDate='20051201 00:00',endDate='20051201 00:18',datum='MLLW',unit=0,timeZone=0) 65 66 67 response = server.getWaterLevelRawSixMin(stationId=str(stationId),beginDate=beginDate,endDate=endDate,datum='MLLW',unit=0,timeZone=0) 68 # only return the last entry 69 return response.item[-1]
70 71 72 ###################################################################### 73 74 if __name__ == '__main__': 75 from optparse import OptionParser 76 myparser = OptionParser(usage="%prog [options]",version="%prog "+__version__) 77 myparser.add_option('--test','--doc-test',dest='doctest',default=False,action='store_true', 78 help='run the documentation tests') 79 #verbosity.addVerbosityOptions(myparser) 80 (options,args) = myparser.parse_args() 81 82 success=True 83 84 if options.doctest: 85 import os; print os.path.basename(sys.argv[0]), 'doctests ...', 86 sys.argv= [sys.argv[0]] 87 #if options.verbosity>=VERBOSE: sys.argv.append('-v') 88 import doctest 89 numfail,numtests=doctest.testmod() 90 if numfail==0: print 'ok' 91 else: 92 print 'FAILED' 93 success=False 94 95 print getWaterLevelSoappyNow(8639348) 96 97 if not success: 98 sys.exit('Something Failed') 99