Question: import pyzipper import os import subprocess import json import time import tempfile import sys from datetime import datetime, timezone import tkinter as tk from tkinter
import pyzipper
import os
import subprocess
import json
import time
import tempfile
import sys
from datetime import datetime, timezone
import tkinter as tk
from tkinter import messagebox, scrolledtext
def displaymessagemessage:
outputtext.inserttkEND, message
def getjobtype:
while True:
jobtype jobtypeentry.getlower
if jobtype in start 'stop', 'exit':
if jobtype 'exit':
displaymessageYou have chosen to exit the automation script"
time.sleep
exit
else:
break
else:
displaymessagePlease type either "start" or "stop" or "exit".
while True:
username osgetloginlower
todaysdate datetime.todaydate
formattedtodaysdate todaysdate.strftimemdYstrip
zpath rC:Program FilesZipzexe"
zippedfile r'file.zip'
passwdpw
with pyzipper.AESZipFilezippedfile, moder as archfolder:
archfolder.setpasswordpasswdencodeutf
userlistnodepath 'users.js
with archfolder.openuserlistnodepath as userlist:
data userlist.readdecodeutf
dataresults datadatafind : data.find
dataformatted dataresults.replacereplace
replace::
dataloads json.loadsdataformatted
if username not in dataloads:
printSorry you are NOT AUTHORIZED to jobtype any automations'
break
elif username in dataloads:
for key, value in dataloads.items:
if key username:
values value
version
startautomations values Cancel
startinputselection
if jobtype 'start':
selecttostartautomationjobtype startautomations, startinputselection, zpath, passwd, zippedfile, username, version
break
def selecttostartautomationjobtype startautomations, startinputselection, zpath, passwd, zippedfile, username, version:
startinputmessage 'Please select the number of the automation you wish to start, or choose strlenstartautomations to CANCEL.
for index, item in enumeratestartautomations:
startinputmessage findexitem
startinputmessage
Your Choice:
displaymessagefstartinputmessage
try:
startuserinput automationentry.get
startuserinput intstartuserinput
if intstartuserinput lenstartautomations:
startinputselection 'valid'
displaymessagefOption selected: Cancel.
time.sleep
elif intstartuserinput and intstartuserinput lenstartautomations:
startinputselection 'valid'
jobname startautomationsintstartuserinput
tempdir tempfile.TemporaryDirectory
outputdir strtempdir.name
subprocess.callzpath, xppasswd, zippedfile, ooutputdir stdoutsubprocess.DEVNULL, stderrsubprocess.STDOUT
stopjobauthorizenodepath outputdir'perms.js
args username jobname, version, jobtype
displaymessagefRequesting API...
subprocess.runnode stopjobauthorizenodepath, args shellTrue, captureoutput True, textTrue, checkTrue
else:
displaymessage That was not a valid number.
except ValueError:
displaymessage That was not a valid number.
root tkTk
root.title API"
outputtext scrolledtext.ScrolledTextroot width height
outputtext.gridrow column columnspan padx pady
jobtypeentrylabel tkLabelroot text"Please type: then click submit"
jobtypeentrylabel.gridrow column padx pady
jobtypeentry tkEntryroot width
jobtypeentry.gridrow column padx pady
automationentrylabel tkLabelroot text"Please type then click submit"
automationentrylabel.gridrow column padx pady
automationentry tkEntryroot width
automationentry.gridrow column padx pady
outputtext.inserttkEND, fDo you want to start stop an automation, or exit the script?
submitbutton tkButtonroot text "Submit", command getjobtype
submitbutton.gridrow column columnspan pady
root.mainloop
Please fix the code. I unable to get the except block to stop displaying, It always displays
file.zip contains 'users.js which has your os username and automations you can run in this format const dictauth thisuser: automation 'automatiuon username is key and values is value
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
