forked from insarlab/PyAPS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmars
32 lines (26 loc) · 866 Bytes
/
mars
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
#!/usr/bin/env python
import sys
import ecmwfapi
import re
import os
import argparse
parser = argparse.ArgumentParser(description='Run MARS request.')
parser.add_argument('infile', nargs='?', default='-', type=argparse.FileType('r'),
help='file containing a MARS request or STDIN otherwise')
args = parser.parse_args()
req = args.infile.read()
print(req)
if "WEBMARS_TARGET" in os.environ:
target = os.environ["WEBMARS_TARGET"]
else:
m = re.search('\\btar(g(e(t)?)?)?\s*=\s*([^\'",\s]+|"[^"]*"|\'[^\']*\')', req, re.I|re.M)
if m is None:
raise Exception("Cannot extract target")
target=m.group(4)
if target is None:
raise Exception("Cannot extract target")
if target[0] == target[-1]:
if target[0] in ['"', "'"]:
target = target[1:-1]
c = ecmwfapi.ECMWFService('mars')
c.execute(req, target)