#!/usr/bin/python
# -------------------------------------------------------------------
# - NAME:        download.py
# - AUTHOR:      Reto Stauffer
# - DATE:        2017-08-04
# -------------------------------------------------------------------
# - DESCRIPTION: This python executable is used to download small
#                manually defined subsets of GFS reforecast v2 grib
#                files. For bulk downloads providing some more
#                settings please check the second executable
#                called GFSV2_bulk.
# -------------------------------------------------------------------
# - EDITORIAL:   2017-08-04, RS: Created file on thinkreto.
# -------------------------------------------------------------------
# - L@ST MODIFIED: 2017-08-05 10:51 on thinkreto
# -------------------------------------------------------------------

import logging
logging.basicConfig(format="# %(levelname)s %(message)s",level=logging.DEBUG)
log = logging.getLogger()

# -------------------------------------------------------------------
# Main part of the script
# -------------------------------------------------------------------
if __name__ == "__main__":

   # ----------------------------------------------------------------
   # Read config file now
   # ----------------------------------------------------------------
   import datetime as dt
   from GFSV2 import *

   # Checking user inputs
   inputs = inputCheck()

   # Read default config file
   config       = readConfig(force_version = inputs.get("version"))
   config.data  = inputs.get("data")
   config.steps = inputs.get("steps")

   # Overrule 'version' from configfile with user input
   if inputs.get("version"): config.version = inputs.get("version")

   # Looping over dates
   for date in inputs.get("dates"):

      # Proccessing
      log.info("Processing date {:s}".format(date.strftime("%Y-%m-%d %HZ")))

      download(config, date)

