#!/usr/bin/env python import sys import ecmwfapi import re import os if len(sys.argv) > 1: req = file(sys.argv[1]).read() else: req = sys.stdin.read() 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)