Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

import pyzipper import os import subprocess import json import time import tempfile from urllib.parse import quote from datetime import datetime, timezone import tkinter as tk

import pyzipper
import os
import subprocess
import json
import time
import tempfile
from urllib.parse import quote
from datetime import datetime, timezone
import tkinter as tk
from tkinter import messagebox, scrolledtext
def get_user_input():
start_user_input = input_text.get("1.0", tk.END)
return start_user_input
def start_automation(jobtype, start_automations, start_input_selection, username, version):
start_input_message = 'Please select the number of the automation you wish to '+ jobtype +', or choose '+ str(len(start_automations))+' to CANCEL.
'
for index, item in enumerate(start_automations):
start_input_message += f'{index+1}){item}
'
start_input_message += 'Your choice: '
output_text.insert(tk.END, start_input_message)
output_text.update_idletasks()
output_text.yview(tk.END)
start_user_input = get_user_input()
print(start_user_input)
def excecute_automation(jobtype):
# get os system username and covert it to lower
username = os.getlogin().lower()
todays_date = datetime.today().date()
formatted_todays_date = todays_date.strftime("%m/%d/%Y").strip('0')
# File path to 7z application to unzip file with json
z_path = r"C:\Program Files\7-Zip\7z.exe"
# File path to zipped folder with nodejs files and nodes packages
zipped_file = r'H:\TEST_Start.zip'
#r'\TEST_Start.zip'
# password to zipped file
passwd= 'password12345678'
# use pyzipper to read file in zipped folders as archive folder
with pyzipper.AESZipFile(zipped_file, mode='r') as arch_folder:
# pass password to password above protected zipped folder
arch_folder.setpassword(passwd.encode('utf-8'))
# Create a variable to TEST_Start_UserList js file to read
userlist_node_path = 'TEST_Start/TEST_Start_UserList.js'
# open js file called /_UserList.js from archived folder
with arch_folder.open(userlist_node_path) as userlist:
# read TEST_Start_UserList.js and covert it to dictionary
data = userlist.read().decode('utf-8')
data_results = data[data.find('{') : data.find('}')+2]
data_formatted = data_results.replace('\'','"').replace('
','\"').replace(':','\":')
# Convert string above into a json object
data_loads = json.loads(data_formatted)
if username not in data_loads:
output_text.insert(tk.END, 'Sorry, you are NOT AUTHORIZED to '+ jobtype +' any automations')
output_text.update_idletasks()
output_text.yview(tk.END)
return
for key, value in data_loads.items():
# if the key in the userlist object above matches the os username
if key == username:
# initialize values to value paired with key above
values = value
version ='0.9'
start_automations = values +['Cancel']
start_input_selection =''
if jobtype == "start":
start_automation(jobtype, start_automations, start_input_selection, username, version)
return jobtype, start_automations, start_input_selection, username, version
if jobtype == "stop":
stop_automation(jobtype, username, formatted_todays_date, z_path, zipped_file, passwd, version)
return jobtype, username, formatted_todays_date, z_path, zipped_file, passwd, version
root= tk.Tk()
root.title("Start or Stop Automation via UiPath Orchestrator API")
start_stop_label = tk.Label(root, text="Do you want to start or stop an automation?")
start_stop_label.pack(pady =5)
button_frame = tk.Frame(root)
button_frame.pack(padx=10, pady =5)
start_button = tk.Button(button_frame, text= "start", command= lambda:excecute_automation("start"))
start_button.pack(side=tk.LEFT, padx=10, pady =5)
stop_button = tk.Button(button_frame, text= "stop", command= lambda: excecute_automation("stop"))
stop_button.pack(side=tk.RIGHT,padx=10, pady =5)
output_text_frame = tk.Frame(root)
output_text_frame.pack(pady=5)
output_text_scrollbar = tk.Scrollbar(output_text_frame)
output_text_scrollbar.pack(side=tk.RIGHT, fill= tk.Y)
output_text = tk.Text(output_text_frame , height=10, width=100, yscrollcommand = output_text_scrollbar.set)
output_text.pack()
output_text_scrollbar.config(command=output_text.yview)
input_text = tk.Text(output_text_frame, height=5, width=100, yscrollcommand = output_text_scrollbar.set)
input_text.pack()
input_button = tk.Button(output_text_frame, text="Make Selection", command = get_user_input())
input_button.pack(side=tk.RIGHT, padx=10, pady =5)
root.mainloop()
I am unable to use input_text as a variable in start automation
please fix the whole code

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions