Files
weewx/bin/wee_reports
2014-11-29 18:15:24 +00:00

72 lines
2.2 KiB
Python
Executable File

#!/usr/bin/env python
#
# Copyright (c) 2009-2014 Tom Keffer <tkeffer@gmail.com>
#
# See the file LICENSE.txt for your full rights.
#
# $Id$
#
"""Module can be called as a main program to generate reports, etc.,
that are current as of the last archive record in the archive database."""
import socket
import syslog
import optparse
import user.extensions #@UnusedImport
import weewx.station
import weewx.reportengine
import weeutil.weeutil
from weeutil.weeutil import timestamp_to_string
description = """Runs all weewx reports. This is a useful debugging tool:
you don't have to wait for the end of an archive interval to run the reports."""
usage = """%prog: [config_file] [timestamp] [--config=CONFIG_FILE] [--help]"""
def main():
# Set defaults for the system logger:
syslog.openlog('wee_reports', syslog.LOG_PID | syslog.LOG_CONS)
# Create a command line parser:
parser = optparse.OptionParser(description=description, usage=usage)
# Add the various options:
parser.add_option("--config", dest="cfgfn", 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_fn, config_dict = weeutil.weeutil.read_config(options.cfgfn, args)
# If the user specified a time, retrieve it. Otherwise, set to None
gen_ts = None if len(args) < 1 else int(args[0])
print "Using configuration file %s." % config_fn
if gen_ts is None:
print "Generating for all time"
else:
print "Generating for time", timestamp_to_string(gen_ts)
# Look for the debug flag. If set, ask for extra logging
weewx.debug = int(config_dict.get('debug', 0))
if weewx.debug:
syslog.setlogmask(syslog.LOG_UPTO(syslog.LOG_DEBUG))
else:
syslog.setlogmask(syslog.LOG_UPTO(syslog.LOG_INFO))
socket.setdefaulttimeout(10)
stn_info = weewx.station.StationInfo(**config_dict['Station'])
t = weewx.reportengine.StdReportEngine(config_dict, stn_info, gen_ts)
# Although the report engine inherits from Thread, we can just run it in the main thread:
t.run()
if __name__=="__main__" :
main()