def get_forecast(latitude, longitude, include_hourly=False, grib2_dir=None): """ Main method determines forecast based on latitude and longitude and returns json-formatted result Args: latitude - forecast point latitude longitude - forecast point longitude include_hourly - flag to include hourly forecast, defaults to false grib2_dir - grib2 data directory, if omitted, the SOAP web service will be used Returns: json-formatted string - see README """ info("Latitude: {0}".format(latitude)) info("Longitude: {0}".format(longitude)) if include_hourly: info("Include hourly forecast") if grib2_dir: info("Using grib2 dir: {0}".format(grib2_dir)) # If grib2 directory is provided, use grib2 files if grib2_dir: grib2.verbose = verbose xml = grib2.xml(grib2_dir, latitude, longitude) info(xml) # Otherwise, use SOAP web service else: xml = noaa_ws.xml(latitude, longitude) info(xml) # Initialize object for data print(forecast.process_xml(xml, include_hourly)) # TODO fix json call
def ndfdXmlclient(): try: # defaults product = 'time-series' begin = end = None elements = [] for key, val in request.args.iteritems(): key = key.lower() if key == 'lat': lat = float(val) elif key == 'lon': lon = float(val) elif key == 'product': if valid_product(val.lower()): product = val.lower() elif key == 'begin': if valid_datetime(val.upper()): begin = val.upper() elif key == 'end': if valid_datetime(val.upper()): end = val.upper() elif key == 'elements': elements = [e for e in val.lower().split(',') if valid_element(e)] if len(elements) == 0: elements = None with mutex: result = grib2.xml(download_dir, lat, lon, elements=elements, product=product, begin=begin, end=end) return result except: abort(400)