-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathbuild_async_query_from_csv.py
executable file
·73 lines (58 loc) · 2.2 KB
/
build_async_query_from_csv.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
#!/usr/bin/env python
import argparse
import sys
import os
import csv
from uframe import UFrame
def main(args):
if args.base_url:
uframe_base = UFrame(base_url=args.base_url)
else:
uframe_env_url = os.getenv('UFRAME_BASE_URL')
if uframe_env_url:
uframe_base = UFrame(base_url=uframe_env_url)
else:
uframe_base = UFrame()
fid = open(args.stream_csv, 'r')
csv_reader = csv.reader(fid)
required_cols = ['stream',
'beginTime',
'endTime',
'sensor',
'method']
cols = csv_reader.next()
# Make sure we have all of the required columns
has_cols = [c for c in required_cols if c in cols]
if len(has_cols) != len(required_cols):
sys.stderr.write('Input csv file missing one or more columns: {:s}\n'.format(args.stream_csv))
sys.stderr.flush()
return 1
c_range = range(0, len(cols))
for r in csv_reader:
rd = {cols[i]:r[i] for i in c_range}
tokens = rd['sensor'].split('-')
if len(tokens) != 4:
sys.stderr.write('Invalid sensor/reference designator specified: {:s}\n'.format(r['sensor']))
sys.stderr.flush()
continue
async_url = '{:s}/{:s}/{:s}/{:s}-{:s}/{:s}/{:s}?beginDT={:s}&endDT={:s}&limit=-1&execDPA=true&format=application/netcdf&include_provenance=true'.format(
uframe_base.url,
tokens[0],
tokens[1],
tokens[2],
tokens[3],
rd['method'],
rd['stream'],
rd['beginTime'],
rd['endTime'])
sys.stdout.write('{:s}\n'.format(async_url))
return 0
if __name__ == '__main__':
arg_parser = argparse.ArgumentParser(description=main.__doc__)
arg_parser.add_argument('stream_csv',
help='Filename containing stream request pieces. Create this file using stream2ref_des_list.py')
arg_parser.add_argument('-b', '--baseurl',
dest='base_url',
help='Specify an alternate uFrame server URL. Must start with \'http://\'.')
parsed_args = arg_parser.parse_args()
sys.exit(main(parsed_args))