Vervangen van {DATE} en {TIME} toegevoegd

This commit is contained in:
Marcel Nijenhof
2019-02-14 23:24:56 +01:00
parent 6b037f1905
commit 7c30138f73
3 changed files with 30 additions and 6 deletions

32
siprun
View File

@@ -5,8 +5,12 @@ import getopt
from lmwsip import LmwSip
def usage():
print("siprun [-s] [-h <host>] [-p <port>] [<files>]")
print("siprun [-H] [-s] [-d <date>] [-t <time>] [-h <host>] [-p <port>] [<files>]")
print("\t-H: Show usage")
print("\t-s: SSL connection")
print("\t-d <date>: Date replacement string (2019-02-14)")
print("\t-t <time>: Time replacement string (17:00)")
print("\t-h <host>: Connect to host")
print("\t-h <host>: Connect to host")
print("\t-p <port>: Connect to port")
print("\t-<files>: LMW commando files")
@@ -20,11 +24,20 @@ def main():
usage()
sys.exit(2)
ssl=False
time=None
date=None
host=None
port=None
for o, a in opts:
if o == "-s":
if o == "-H":
usage()
sys.exit(0)
elif o == "-s":
ssl=True
elif o == "-d":
date=a
elif o == "-t":
time=a
elif o == "-h":
host=a
elif o == "-p":
@@ -34,11 +47,22 @@ def main():
usage()
sys.exit(3)
lmwsip = LmwSip(ssl=ssl, host=host, port=port)
if (date == None or time == None):
# We assume a 10 minut interval so we use H10
r = lmwsip.lasttime("H10")
print(r)
if (date == None):
date = r["day"]
if (time == None):
time = r["time_of_day"]
for cmdfile in args:
with open(cmdfile, "r") as f:
for cmd in f:
print("> [%s]" % (cmd.strip('\n')))
lmwsip.send(cmd.replace('\n', '\r'))
cmd = cmd.replace('{DATE}', date)
cmd = cmd.replace('{TIME}', time)
cmd = cmd.replace('\n', '\r')
print("> [%s]" % (cmd.strip('\r')))
lmwsip.send(cmd)
print("< [%s]" % (lmwsip.recv().decode('utf-8').strip('\r')))
f.close()