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

Source Code for Module noaadata.waterlevelraw

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