Merge branch 'master' into startOfArchiveDay

# Conflicts:
#	docs/changes.txt
This commit is contained in:
Tom Keffer
2022-07-05 10:01:12 -07:00
5 changed files with 149 additions and 37 deletions

View File

@@ -1,6 +1,6 @@
#!/usr/bin/env python
#
# Copyright (c) 2009-2021 Tom Keffer <tkeffer@gmail.com>
# Copyright (c) 2009-2022 Tom Keffer <tkeffer@gmail.com>
#
# 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()

View File

@@ -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)

View File

@@ -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

View File

@@ -249,6 +249,27 @@ sudo apt-get install weewx</pre>
<h1><a id="Instructions_for_specific_versions">Instructions for specific versions</a></h1>
<h2>Upgrading to V4.9</h2>
<h3><span class="code">wee_reports</span> may require <span class="code">--epoch</span> option.</h3>
<p>
In previous versions, the utility <span class="code">wee_reports</span> could take an optional
position argument that specified the reporting time in unix epoch time. For example,
</p>
<pre class="tty cmd">wee_reports /home/weewx/weewx.conf 1645131600</pre>
<p>
would specify that the reporting time should be 1645131600, or 17-Feb-2022 13:00 PST.
</p>
<p>
Starting with V4.9, the unix epoch time must be specified using the <span class="code">--epoch</span>
flag, so the command becomes
</p>
<pre class="tty cmd">wee_reports /home/weewx/weewx.conf --epoch=1645131600</pre>
<p>
Alternatively, the reporting time can be specified by using <span class="code">--date</span> and
<span class="code">--time</span> flags:
</p>
<pre class="tty cmd">wee_reports /home/weewx/weewx.conf --date=2022-02-17 --time=13:00</pre>
<h2>Upgrading to V4.6</h2>
<h3>Ordering of search list changed</h3>
<p>

View File

@@ -4524,17 +4524,59 @@ Aug 22 14:38:28 stretch12 weewx[863]: manager: unable to add record 2018-09-04 0
<p>This results in something like this:</p>
<pre class="tty">Usage: wee_reports: [config_file] [timestamp] [--config=CONFIG_FILE] [--help]
<pre class="tty">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.
</pre>
<p>
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 <span class="code">--epoch</span>, or by using options
<span class="code">--date</span> and <span class="code">--time</span>.
</p>
<h2>Options</h2>
<h3>Option <span class="code">--config</span></h3>
<p>
An optional path to the configuration file (usually, <span class="code">weewx.conf</span>) can be given
as either a positional argument, or by using option <span class="code">--config</span> (but not both).
If not given, the location of the configuration file will be inferred.
</p>
<h3>Option <span class="code">--epoch</span></h3>
<p>
If given, generate the reports so that they are current as of the given unix epoch time. Example:
</p>
<pre class="tty cmd">wee_reports --epoch=1652367600</pre>
<p>
This would generate a report for unix epoch time 1652367600 (12-May-2022 at 8AM PDT).
</p>
<h3>Option <span class="code">--date</span><br/>
Option <span class="code">--time</span></h3>
<p>
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 <span class="code">YYYY-MM-DD</span> and the time should be given as
<span class="code">HH:DD</span>. Example:
</p>
<pre class="tty cmd">wee_reports /home/weewx/weewx.conf --date=2022-05-12 --time=08:00</pre>
<p>
This would generate a report for 12-May-2022 at 8AM (unix epoch time 1652367600).
</p>
<!-- ======== -->