#!/usr/bin/env python3

"""Communicates with the smart electricity meter [KAMSTRUP]."""

import configparser
import datetime as dt
import os
import re
import sqlite3
import sys
import syslog
import time
import traceback

import mausy5043funcs.fileops3 as mf

# constants
DEBUG       = False
IS_JOURNALD = os.path.isfile('/bin/journalctl')
MYID        = "".join(list(filter(str.isdigit, os.path.realpath(__file__).split('/')[-1])))
MYAPP       = os.path.realpath(__file__).split('/')[-3]
NODE        = os.uname()[1]


if __name__ == "__main__":
  # initialise logging
  syslog.openlog(ident=MYAPP, facility=syslog.LOG_LOCAL0)

@@ -510,16 +510,834 @@
 ()%5B1%5D%0A%0A%0A
+def get_cli_params():%0A    %22%22%22Check for presence of a CLI parameter.%22%22%22%0A    if len(sys.argv) != 2:%0A        sys.exit(0)%0A    # 1 parameter required = filename to be processed%0A    return sys.argv%5B1%5D%0A%0A%0Adef read_file(file_to_read_from):%0A    %22%22%22%0A    Return the contents of a file if it exists.%0A%0A    Abort if it doesn't exist.%0A    %22%22%22%0A    if not os.path.isfile(file_to_read_from):%0A        sys.exit(0)%0A    with open(file_to_read_from, 'r') as input_file:%0A        # read the inputfile%0A        return input_file.read().splitlines()%0A%0A%0Adef write_file(file_to_write_to, lines_to_write):%0A    %22%22%22%0A    Output %3Clines_to_write%3E to the file %3Cfile_to_write_to%3E.%0A%0A    Will overwrite existing file.%0A    %22%22%22%0A    with open(file_to_write_to, 'w') as output_file:%0A        for line in lines_to_write:%0A            output_file.write(f'%7Bline%7D%5Cn')%0A%0A%0A
 if __nam
@@ -1436,8 +1436,89 @@
 LOCAL0)%0A
+  ifile = get_cli_params()%0A  lines = read_file(ifile)%0A  print(lines.split(', '))%0A

read a file