71 lines
2.0 KiB
Python
Executable File
71 lines
2.0 KiB
Python
Executable File
#!/usr/bin/python3
|
|
|
|
import sys
|
|
import getopt
|
|
from lmwsip import LmwSip
|
|
|
|
def usage():
|
|
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")
|
|
|
|
def main():
|
|
try:
|
|
opts, args = getopt.getopt(sys.argv[1:], "sh:p:d:t:", ["help", "output="])
|
|
except getopt.GetoptError as err:
|
|
# print help information and exit:
|
|
print(err) # will print something like "option -a not recognized"
|
|
usage()
|
|
sys.exit(2)
|
|
ssl=False
|
|
time=None
|
|
date=None
|
|
host=None
|
|
port=None
|
|
for o, a in opts:
|
|
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":
|
|
port=a
|
|
if (host==None or port==None):
|
|
print("Set host and port")
|
|
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:
|
|
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()
|
|
|
|
if __name__ == "__main__":
|
|
main()
|