diff --git a/bin/wee_reports b/bin/wee_reports index 6e03b4aa..3ecf0d81 100755 --- a/bin/wee_reports +++ b/bin/wee_reports @@ -1,6 +1,6 @@ #!/usr/bin/env python # -# Copyright (c) 2009-2021 Tom Keffer +# Copyright (c) 2009-2022 Tom Keffer # # See the file LICENSE.txt for your rights. # @@ -9,10 +9,14 @@ from __future__ import absolute_import from __future__ import print_function -import optparse +import argparse import socket +import sys +import time -# Although this import is not used, it's important to execute any user extensions before starting. +# Although 'user.extensions' is not used, it's important to execute any user extensions +# before starting. +# noinspection PyUnresolvedReferences import user.extensions import weecfg import weeutil.logger @@ -26,7 +30,13 @@ description = """Run all reports defined in the specified configuration file. Use this utility to run reports immediately instead of waiting for the end of an archive interval.""" -usage = """%prog: [config_file] [timestamp] [--config=CONFIG_FILE] [--help]""" +usage = """%(prog)s --help + %(prog)s [CONFIG_FILE | --config=CONFIG_FILE] + %(prog)s [CONFIG_FILE | --config=CONFIG_FILE] --epoch=TIMESTAMP + %(prog)s [CONFIG_FILE | --config=CONFIG_FILE] --date=YYYY-MM-DD --time=HH:MM""" + +epilog = "Specify either the positional argument CONFIG_FILE, " \ + "or the optional argument --config, but not both." def disable_timing(section, key): @@ -37,15 +47,52 @@ def disable_timing(section, key): def main(): # Create a command line parser: - parser = optparse.OptionParser(description=description, usage=usage) + parser = argparse.ArgumentParser(description=description, usage=usage, epilog=epilog, + prog='wee_reports') # Add the various options: - parser.add_option("--config", dest="config_path", type=str, metavar="CONFIG_FILE", - help="Use the configuration file CONFIG_FILE") + parser.add_argument("--config", dest="config_option", metavar="CONFIG_FILE", + help="Use the configuration file CONFIG_FILE") + parser.add_argument("--epoch", metavar="EPOCH_TIME", + help="Time of the report in unix epoch time") + parser.add_argument("--date", metavar="YYYY-MM-DD", + type=lambda d: time.strptime(d, '%Y-%m-%d'), + help="Date for the report") + parser.add_argument("--time", metavar="HH:MM", + type=lambda t: time.strptime(t, '%H:%M'), + help="Time of day for the report") + parser.add_argument("config_arg", nargs='?', metavar="CONFIG_FILE") # Now we are ready to parse the command line: - options, args = parser.parse_args() - config_path, config_dict = weecfg.read_config(options.config_path, args) + namespace = parser.parse_args() + + # User can specify the config file as either a positional argument, or as an option + # argument, but not both. + if namespace.config_option and namespace.config_arg: + sys.exit(epilog) + # Presence of --date requires --time and v.v. + if namespace.date and not namespace.time or namespace.time and not namespace.date: + sys.exit("Must specify both --date and --time.") + # Can specify the time as either unix epoch time, or explicit date and time, but not both + if namespace.epoch and namespace.date: + sys.exit("The time of the report must be specified either as unix epoch time, " + "or with an explicit date and time, but not both.") + + # If the user specified a time, retrieve it. Otherwise, set to None + if namespace.epoch: + gen_ts = int(namespace.epoch) + elif namespace.date: + gen_ts = get_epoch_time(namespace.date, namespace.time) + else: + gen_ts = None + + if gen_ts is None: + print("Generating as of last timestamp in the database.") + else: + print("Generating for requested time %s" % timestamp_to_string(gen_ts)) + + # Fetch the config file + config_path, config_dict = weecfg.read_config(namespace.config_arg, [namespace.config_option]) print("Using configuration file %s" % config_path) # Look for the debug flag. If set, ask for extra logging @@ -67,14 +114,6 @@ def main(): stn_info = weewx.station.StationInfo(**config_dict['Station']) - # If the user specified a time, retrieve it. Otherwise, set to None - gen_ts = int(args[0]) if args else None - - if gen_ts is None: - print("Generating for all time") - else: - print("Generating for requested time %s" % timestamp_to_string(gen_ts)) - try: binding = config_dict['StdArchive']['data_binding'] except KeyError: @@ -98,5 +137,12 @@ def main(): # Shut down any running services, engine.shutDown() + +def get_epoch_time(d_tt, t_tt): + tt = (d_tt.tm_year, d_tt.tm_mon, d_tt.tm_mday, + t_tt.tm_hour, t_tt.tm_min, 0, 0, 0, -1) + return time.mktime(tt) + + if __name__ == "__main__": main() diff --git a/bin/weewx/tests/test_almanac.py b/bin/weewx/tests/test_almanac.py index 349b5440..d1830c6d 100644 --- a/bin/weewx/tests/test_almanac.py +++ b/bin/weewx/tests/test_almanac.py @@ -96,9 +96,9 @@ class AlmanacTest(unittest.TestCase): self.almanac.venus.cmlI def test_star(self): - self.assertEqual(str(self.almanac.rigel.rise), "12:32:33") - self.assertEqual(str(self.almanac.rigel.transit), "18:00:38") - self.assertEqual(str(self.almanac.rigel.set), "23:28:43") + self.assertEqual(str(self.almanac.castor.rise), "11:36:37") + self.assertEqual(str(self.almanac.castor.transit), "20:20:28") + self.assertEqual(str(self.almanac.castor.set), "05:08:16") def test_sidereal(self): self.assertAlmostEqual(self.almanac.sidereal_time, 348.3400, 4) diff --git a/docs/changes.txt b/docs/changes.txt index 9fdd31d5..2d1a84de 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -1,16 +1,12 @@ WeeWX change history -------------------- -4.8.1 MM/DD/YYYY -Don't swallow syntax errors when wee_config is looking for drivers. - +4.9.0 MM/DD/YYYY Fix problem that create 'ghost' values for VantageVue stations. Fix problem that causes `leafWet3` and `leafWet4` to be emitted in VP2 stations that do not have the necessary sensors. Fixes issue #771. -Include 'wind' in daily summary if 'windSpeed' is present. - Try waking the Vantage console before giving up on LOOP errors. Better Vantage diagnostics. Fixes issue #772. @@ -18,19 +14,26 @@ Fixes issue #772. Add missing 30-day barometer graph to Smartphone skin. Fixes issue #774. -Refine translations for French skin. Thanks to user Pascal! - Fix check for reuse_ssl for Python versions greater than 3.10. Fixes issue #775. -Allow a custom cipher to be specified for FTP uploads. See option 'cipher' -under [[FTP]]. +The utility wee_reports can now be invoked by specifying a --date and --time. +Fixes issue #776. + +Allow timestamps that are not integers. +Fixes issue #779. Add localization file for Traditional Chinese. Thanks to user lyuxingliu! PR #777. -Allow timestamps that are not integers. -Fixes issue #779. +Don't swallow syntax errors when wee_config is looking for drivers. + +Include 'wind' in daily summary if 'windSpeed' is present. + +Refine translations for French skin. Thanks to user Pascal! + +Allow a custom cipher to be specified for FTP uploads. See option 'cipher' +under [[FTP]]. 4.8.0 04/21/2022 diff --git a/docs/upgrading.htm b/docs/upgrading.htm index 4de6901d..7b6f0726 100644 --- a/docs/upgrading.htm +++ b/docs/upgrading.htm @@ -249,6 +249,27 @@ sudo apt-get install weewx

Instructions for specific versions

+

Upgrading to V4.9

+

wee_reports may require --epoch option.

+

+ In previous versions, the utility wee_reports could take an optional + position argument that specified the reporting time in unix epoch time. For example, +

+
wee_reports /home/weewx/weewx.conf 1645131600
+

+ would specify that the reporting time should be 1645131600, or 17-Feb-2022 13:00 PST. +

+

+ Starting with V4.9, the unix epoch time must be specified using the --epoch + flag, so the command becomes +

+
wee_reports /home/weewx/weewx.conf --epoch=1645131600
+

+ Alternatively, the reporting time can be specified by using --date and + --time flags: +

+
wee_reports /home/weewx/weewx.conf --date=2022-02-17 --time=13:00
+

Upgrading to V4.6

Ordering of search list changed

diff --git a/docs/utilities.htm b/docs/utilities.htm index 531a9c4b..402c0bff 100644 --- a/docs/utilities.htm +++ b/docs/utilities.htm @@ -4524,17 +4524,59 @@ Aug 22 14:38:28 stretch12 weewx[863]: manager: unable to add record 2018-09-04 0

This results in something like this:

-
Usage: wee_reports: [config_file] [timestamp] [--config=CONFIG_FILE] [--help]
+        
usage: wee_reports --help
+       wee_reports [CONFIG_FILE | --config=CONFIG_FILE]
+       wee_reports [CONFIG_FILE | --config=CONFIG_FILE] --epoch=TIMESTAMP
+       wee_reports [CONFIG_FILE | --config=CONFIG_FILE] --date=YYYY-MM-DD --time=HH:MM
 
-Run all reports defined in the specified configuration file. Use this utility
-to run reports immediately instead of waiting for the end of an archive
-interval.
+Run all reports defined in the specified configuration file. Use this utility to run reports immediately instead of waiting for the end of
+an archive interval.
 
-Options:
+positional arguments:
+  CONFIG_FILE
+
+optional arguments:
   -h, --help            show this help message and exit
-  --config=CONFIG_FILE  Use the configuration file CONFIG_FILE
+  --config CONFIG_FILE  Use the configuration file CONFIG_FILE
+  --epoch EPOCH_TIME    Time of the report in unix epoch time
+  --date YYYY-MM-DD     Date for the report
+  --time HH:MM          Time of day for the report
+
+Specify either the positional argument CONFIG_FILE, or the optional argument --config, but not both.
 
+

+ By default, the reports are generated as of the last timestamp in the database, however, an explicit + time can be given by using either option --epoch, or by using options + --date and --time. +

+

Options

+

Option --config

+

+ An optional path to the configuration file (usually, weewx.conf) can be given + as either a positional argument, or by using option --config (but not both). + If not given, the location of the configuration file will be inferred. +

+

Option --epoch

+

+ If given, generate the reports so that they are current as of the given unix epoch time. Example: +

+
wee_reports --epoch=1652367600
+

+ This would generate a report for unix epoch time 1652367600 (12-May-2022 at 8AM PDT). +

+

Option --date
+ Option --time

+

+ If given, generate the reports so that they are current as of the given date and time. The date should + be given in the form YYYY-MM-DD and the time should be given as + HH:DD. Example: +

+
wee_reports /home/weewx/weewx.conf --date=2022-05-12 --time=08:00
+

+ This would generate a report for 12-May-2022 at 8AM (unix epoch time 1652367600). +

+