Answers for "transcoder converter for python to java"

C
0

transcoder converter for python to java

def import_file(file):
    with open(file,"r") as f:
        lines = f.readlines()
        sline = []
        for line in lines:
          xline=line.split(" ")
          sline.append(xline)
    return sline        
        
def set_file(idf,q,sline):
    for i in sline:
        if idf in i:
            sline[sline.index(i)][1] = q + "n"
            return "Change succeeded"
    sline.append([idf,q])
    return "New code added"

def list_file(idf,sline):
    for i in sline:
        if idf in i:
            return sline[sline.index(i)][1]
    return "Not found"       

def export_file(name,sline):
    with open(name,'w') as f:
        for lines in sline:
            f.write(lines[0] + ' ' + lines[1])
                                     
loop = 1
while loop == 1:
    choice=int(input("1:Import filen 2:Set n 3:List n 4:Export file n 5:Quit n :"))
    if choice == 1:
        print("Importing file...")
        use=import_file(input("Insert the path of the file:"))
    elif choice == 2:
        print("Setting file...")
        print(set_file(input("Insert id:"),input("Insert quantity:"),use))
    elif choice == 3:
        print("Listing file...")
        print(list_file(input("Insert id:"),use))
        print(use)
    elif choice == 4:
        print("Exporting file...")
        print(export_file(input("Name of the exported file:"),use))
    elif choice == 5:
        print("Goodbye")
        loop = 0
Posted by: Guest on November-12-2021
-1

Convert Python to Java translator online

#import libraries
import os, subprocess, time, shutil
from datetime import datetime

#format date to nonflex standard
def formatdate(date, time):
    input= date+time
    output= datetime.strptime(input, "%d%b%y%H:%M:%S:").strftime("%m/%d/%Y|%H:%M:%S")
    return output

# stop the service, copy the log file to C:NonFlexRotatedLogs and start service
service_status = subprocess.run(['sc', 'stop', 'ghs_lm'])
time.sleep(10)
shutil.move("C:\NonFlex\DebugLogs\ghs.dl.rtf","C:\NonFlex\RotatedLogs\"+"ghslm_"+str(datetime.now().strftime("%Y%m%d"))+"_ts-apps15.rl")
service_status = subprocess.run(['sc', 'start', 'ghs_lm'])

#pass log file into script
filename = ("C:\NonFlex\RotatedLogs\"+"ghslm_"+str(datetime.now().strftime("%Y%m%d"))+"_ts-apps15.rl")
with open(filename) as g:
    content = g.readlines()

#create log file for output
filename = ("C:\NonFlex\ReportLogs\"+"ghslm_"+str(datetime.now().strftime("%Y%m%d"))+"_ts-apps15.log")
f= open(filename,"w+")

#parse the lines in the file
for line in content:
    line=line.split()
    try:
        date=formatdate(line[0],line[1])
    except:
        continue
    #process license checkouts | working
    if "granted" in line:
        username=(line[8].split("@")[0])
        ipaddress=(line[8].split("@")[1])
        feature=line[3]
        f.write(date+"|OUT|"+feature+"|1|0|"+username+"|"+ipaddress+"n")
    #process license checkins
    if "exit" in line or "released" in line:
        #process checkin
        if line[2]=="exit":
            username=(line[4].split("@")[0])
            ipaddress=(line[4].split("@")[1])
            feature=line[3]
        else:
            username=(line[2].split("@")[0])
            ipaddress=(line[2].split("@")[1])
            feature=line[4]     
        f.write(date+"|IN|"+feature+"|1|0|"+username+"|"+ipaddress+"n")
    #log license startup| Working
    if "Starting" in line and "License" in line:
        f.write(formatdate(line[0],line[1])+"|START"+"n")
    #log license shutdowns| Working
    if "Exiting" in line:
        f.write(formatdate(line[0],line[1])+"|END"+"n")
    if "Feature" in line:
        date=formatdate(line[0],line[1])
        quantity=line[5]
        feature=(line[4][1:-2])
        f.write(date+"|FEATURE|"+feature+"|"+quantity+"n")

#close file and copy to \orl4dfsns1.us.lmco.comorlandoscoc_dfsLicAdmNonFlexPC
f.close()
shutil.copyfile(filename,"\\orl4dfsns1.us.lmco.com\orlando\scoc_dfs\LicAdm\NonFlexPC\"+"ghslm_"+str(datetime.now().strftime("%Y%m%d"))+"_ts-apps15.log")
Posted by: Guest on June-23-2021

Code answers related to "C"

Browse Popular Code Answers by Language