Commit 6b4ac2a3 authored by Dan Baston's avatar Dan Baston

Avoid trying to download forecast before it has been issued

parent e9115a6b
......@@ -26,6 +26,7 @@ import datetime
import os
from urllib.request import urlopen
def parse_args(args):
parser = argparse.ArgumentParser('Download a CFSv2 forecast GRIB file')
......@@ -43,6 +44,7 @@ def parse_args(args):
return parsed
def download(url, output_dir):
fname = url.rsplit('/', 1)[-1]
......@@ -72,6 +74,10 @@ def main(raw_args):
start_of_rolling_archive = - datetime.timedelta(days=6) # should have 7 days but doesn't always
timestamp_datetime = datetime.datetime(year, month, day, hour)
if timestamp_datetime > datetime.datetime.utcnow():
print("Can't download forecast with timestamp in the future.", file=sys.stderr)
if timestamp_datetime > start_of_rolling_archive:
print("Using rolling archive URL")
url_patterns = (
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment