Add num_hrs_to_fetch var
[infoex-autowx.git] / infoex-autowx.py
index a1bcf004ef9900b42f33196a52a4ff7fa632bd69..2b7880eaf9865acad39b83c6a56d8b5e1a55f92c 100755 (executable)
@@ -128,6 +128,12 @@ def setup_config(config):
             LOG.critical("%s is not a valid timezone", tz)
             sys.exit(1)
 
             LOG.critical("%s is not a valid timezone", tz)
             sys.exit(1)
 
+        # By default, fetch three hours of data
+        #
+        # If user wants hn24 or wind averaging, then
+        # we need more.
+        station['num_hrs_to_fetch'] = 3
+
         # HN24
         if 'hn24' in config['station']:
             if config['station']['hn24'] not in ['true', 'false']:
         # HN24
         if 'hn24' in config['station']:
             if config['station']['hn24'] not in ['true', 'false']:
@@ -135,6 +141,7 @@ def setup_config(config):
 
             if config['station']['hn24'] == "true":
                 station['hn24'] = True
 
             if config['station']['hn24'] == "true":
                 station['hn24'] = True
+                station['num_hrs_to_fetch'] = 24
             else:
                 station['hn24'] = False
         else:
             else:
                 station['hn24'] = False
         else:
@@ -147,6 +154,9 @@ def setup_config(config):
                 raise ValueError("wind_mode must be either 'normal' or 'average'")
 
             station['wind_mode'] = config['station']['wind_mode']
                 raise ValueError("wind_mode must be either 'normal' or 'average'")
 
             station['wind_mode'] = config['station']['wind_mode']
+
+            if station['wind_mode'] == "average":
+                station['num_hrs_to_fetch'] = 24
         else:
             # default to False
             station['wind_mode'] = "normal"
         else:
             # default to False
             station['wind_mode'] = "normal"
@@ -632,7 +642,7 @@ def setup_time_values(station):
     end_date = date_time - datetime.timedelta(minutes=date_time.minute % 60,
                                               seconds=date_time.second,
                                               microseconds=date_time.microsecond)
     end_date = date_time - datetime.timedelta(minutes=date_time.minute % 60,
                                               seconds=date_time.second,
                                               microseconds=date_time.microsecond)
-    begin_date = end_date - datetime.timedelta(hours=3)
+    begin_date = end_date - datetime.timedelta(hours=station['num_hrs_to_fetch'])
     return (begin_date, end_date)
 
 def f_to_c(f):
     return (begin_date, end_date)
 
 def f_to_c(f):