Files
weewx/bin/wee_reports

70 lines
2.1 KiB
Python
Executable File

#!/usr/bin/env python
#
# Copyright (c) 2009-2019 Tom Keffer <tkeffer@gmail.com>
#
# See the file LICENSE.txt for your rights.
#
"""Executable that can run all reports."""
from __future__ import absolute_import
from __future__ import print_function
import optparse
import socket
import weecfg
import weeutil.logger
import weewx.reportengine
import weewx.station
from weeutil.weeutil import timestamp_to_string
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]"""
def main():
# Set defaults for logging:
weeutil.logger.setup('wee_reports', {})
# Create a command line parser:
parser = optparse.OptionParser(description=description, usage=usage)
# Add the various options:
parser.add_option("--config", dest="config_path", type=str, metavar="CONFIG_FILE",
help="Use the configuration file 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)
# If the user specified a time, retrieve it. Otherwise, set to None
gen_ts = int(args[0]) if args else None
print("Using configuration file %s" % config_path)
if gen_ts is None:
print("Generating for all time")
else:
print("Generating for requested time %s" % timestamp_to_string(gen_ts))
# Look for the debug flag. If set, ask for extra logging
weewx.debug = int(config_dict.get('debug', 0))
# Set final configuration for logging:
weeutil.logger.setup('wee_reports', config_dict)
socket.setdefaulttimeout(10)
stn_info = weewx.station.StationInfo(**config_dict['Station'])
t = weewx.reportengine.StdReportEngine(config_dict, stn_info, gen_ts=gen_ts)
# Although the report engine inherits from Thread, we can just run it in the main thread:
t.run()
if __name__=="__main__" :
main()