forked from NOAA-PMEL/EcoFOCI_ArgosDataOps
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgetARGO_SOAP.py
114 lines (94 loc) · 3.61 KB
/
getARGO_SOAP.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
"""
Purpose:
Using SOAP protocol to connect to argo service for drifter and weatherpak data access
Usage:
python getARGO_SOAP getCsv #gets csv files expected by parser routines
python getARGO_SOAP getKml #gets google earth kml file
Returns:
previous days data from ARGO soap server as file data/results.{filetype}
Author: S.Bell
History:
2018-03-14: Make it so either the program number or platform id can be submitted
Note:
To get an idea of all functions available
python -mzeep http://ws-argos.clsamerica.com/argosDws/services/DixService?wsdl
"""
import argparse
import datetime
import zeep
# parse incoming command line options
parser = argparse.ArgumentParser(description='Connect to argos.cls SOAP server for FOCI')
parser.add_argument('username',
metavar='username',
type=str,
help='program username')
parser.add_argument('password',
metavar='password',
type=str,
help='program password')
parser.add_argument('service',
metavar='service',
type=str,
help='getCsv | getObsCsv | getXml | getKml | getXsd')
parser.add_argument('-idMode','--idMode',
type=str,
default='programNumber',
help='programNumber | platformId')
parser.add_argument('-idnumber', '--idnumber',
type=str,
default='572',
help='programNumber: or platformId number desired')
parser.add_argument('-startDate','--startDate',
type=str,
default='today',
help='startDate for retrieval in yyyy-mm-ddThh:mm:ss')
parser.add_argument('-recordlength','--recordlength',
type=int,
default=86400,
help='length of records to retrieve in seconds (default is 86400)')
args = parser.parse_args()
client = zeep.Client('http://ws-argos.clsamerica.com/argosDws/services/DixService?wsdl')
if args.startDate:
if args.startDate in ['today']:
startDate = datetime.date.today()-datetime.timedelta(seconds=24*60*60)
endDate = datetime.date.today()
else:
startDate = datetime.datetime.strptime(args.startDate,'%Y-%m-%dT%H:%M:%S')
endDate = startDate + datetime.timedelta(seconds=args.recordlength)
argodic = {'username':args.username,
'password':args.password,
args.idMode:args.idnumber,
'period':{'startDate':startDate,'endDate':endDate},
'mostRecentPassages':True,
'showHeader':True,
'displayLocation':True,
'displayDiagnostic':True,
'displaySensor':True}
if args.service in ['getCsv']:
result = client.service.getCsv(**argodic)
filetype = 'csv'
if args.service in ['getObsCsv']:
subkeys = ('username', 'password', args.idMode,'period')
subdict = {x: argodic[x] for x in subkeys if x in argodic}
result = client.service.getObsCsv(**subdict)
filetype = 'obs.csv'
if args.service in ['getXml']:
subkeys = ('username', 'password', args.idMode,'period',
'displayLocation','displayDiagnostic','displaySensor')
subdict = {x: argodic[x] for x in subkeys if x in argodic}
result = client.service.getXml(**subdict)
filetype = 'xml'
if args.service in ['getKml']:
subkeys = ('username', 'password', args.idMode,'period')
subdict = {x: argodic[x] for x in subkeys if x in argodic}
result = client.service.getKml(**subdict)
filetype = 'kml'
datestr = startDate.strftime('%Y%m%d%H%M%S')+'_'+endDate.strftime('%Y%m%d%H%M%S')
if args.idMode in ['programNumber']:
with open("data/" + ".".join(['ARGO_'+datestr,filetype]), 'w') as f:
f.write(result)
elif args.idMode in ['platformId']:
with open("data/" + ".".join(['ARGO_'+args.idnumber+'_'+datestr,filetype]), 'w') as f:
f.write(result)
else:
print("No file written")