-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
53 lines (37 loc) · 1.64 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import argparse
import os
import logging
import sys
from rpi_watermeter import watermeter
logger = logging.getLogger(__name__)
LOG_FORMAT = "%(asctime)s [%(levelname)s] %(name)s %(message)s"
LOG_FORMAT_VERBOSE = "%(asctime)s [%(levelname)s] %(name)s %(filename)s.%(lineno)d %(message)s"
CONFIG_FILE = ".watermeter.conf"
if __name__ == "__main__":
parser = argparse.ArgumentParser("watermeter app", fromfile_prefix_chars='@')
parser.add_argument('--db-host', required=True, help="InfluxDB Hostname & port")
parser.add_argument('--db-token', required=True, help="InfluxDB token for access")
parser.add_argument('--db-org', help="InfluxDB token for access", default="watermeter")
parser.add_argument('--db-bucket', help="InfluxDB Bucket name for the flow data", default="watermeter")
parser.add_argument('--db-raw-bucket', help="InfluxDB bucket name for raw data. If not specified, no raw data is logged")
parser.add_argument('-v', '--verbose', action='count', default=0)
argv = sys.argv[1:]
if os.path.exists(CONFIG_FILE):
argv = ['@%s' % CONFIG_FILE] + argv
args = parser.parse_args(argv)
log_level = logging.INFO
log_format = LOG_FORMAT
if args.verbose > 0:
log_level = logging.DEBUG
if args.verbose > 1:
log_format = LOG_FORMAT_VERBOSE
logging.basicConfig(format=log_format, level=log_level)
settings = watermeter.Settings(
db_host=args.db_host,
db_org=args.db_org,
db_token=args.db_token,
bucket_name=args.db_bucket,
)
if args.db_raw_bucket:
settings.raw_bucket_name = args.db_raw_bucket
watermeter.run(settings=settings)