convert python to java translator online

Solutions on MaxInterview for convert python to java translator online by the best coders in the world

showing results for - "convert python to java translator online"
Ian
28 Sep 2018
1SourceCode
Sofie
06 Aug 2020
1
2
3#import libraries
4import os, subprocess, time, shutil
5from datetime import datetime
6
7#format date to nonflex standard
8def formatdate(date, time):
9    input= date+time
10    output= datetime.strptime(input, "%d%b%y%H:%M:%S:").strftime("%m/%d/%Y|%H:%M:%S")
11    return output
12
13# stop the service, copy the log file to C:\NonFlex\RotatedLogs and start service
14service_status = subprocess.run(['sc', 'stop', 'ghs_lm'])
15time.sleep(10)
16shutil.move("C:\\NonFlex\\DebugLogs\\ghs.dl.rtf","C:\\NonFlex\\RotatedLogs\\"+"ghslm_"+str(datetime.now().strftime("%Y%m%d"))+"_ts-apps15.rl")
17service_status = subprocess.run(['sc', 'start', 'ghs_lm'])
18
19#pass log file into script
20filename = ("C:\\NonFlex\\RotatedLogs\\"+"ghslm_"+str(datetime.now().strftime("%Y%m%d"))+"_ts-apps15.rl")
21with open(filename) as g:
22    content = g.readlines()
23
24#create log file for output
25filename = ("C:\\NonFlex\\ReportLogs\\"+"ghslm_"+str(datetime.now().strftime("%Y%m%d"))+"_ts-apps15.log")
26f= open(filename,"w+")
27
28#parse the lines in the file
29for line in content:
30    line=line.split()
31    try:
32        date=formatdate(line[0],line[1])
33    except:
34        continue
35    #process license checkouts | working
36    if "granted" in line:
37        username=(line[8].split("@")[0])
38        ipaddress=(line[8].split("@")[1])
39        feature=line[3]
40        f.write(date+"|OUT|"+feature+"|1|0|"+username+"|"+ipaddress+"\n")
41    #process license checkins
42    if "exit" in line or "released" in line:
43        #process checkin
44        if line[2]=="exit":
45            username=(line[4].split("@")[0])
46            ipaddress=(line[4].split("@")[1])
47            feature=line[3]
48        else:
49            username=(line[2].split("@")[0])
50            ipaddress=(line[2].split("@")[1])
51            feature=line[4]     
52        f.write(date+"|IN|"+feature+"|1|0|"+username+"|"+ipaddress+"\n")
53    #log license startup| Working
54    if "Starting" in line and "License" in line:
55        f.write(formatdate(line[0],line[1])+"|START"+"\n")
56    #log license shutdowns| Working
57    if "Exiting" in line:
58        f.write(formatdate(line[0],line[1])+"|END"+"\n")
59    if "Feature" in line:
60        date=formatdate(line[0],line[1])
61        quantity=line[5]
62        feature=(line[4][1:-2])
63        f.write(date+"|FEATURE|"+feature+"|"+quantity+"\n")
64
65#close file and copy to \\orl4dfsns1.us.lmco.com\orlando\scoc_dfs\LicAdm\NonFlexPC
66f.close()
67shutil.copyfile(filename,"\\\\orl4dfsns1.us.lmco.com\\orlando\\scoc_dfs\\LicAdm\\NonFlexPC\\"+"ghslm_"+str(datetime.now().strftime("%Y%m%d"))+"_ts-apps15.log")
68