def Open_New_3270(self): '''Closes all previous instances before starting''' self.process_name = 'wc3270.exe' self.get_pid = [ self.item.split()[1] for self.item in os.popen('tasklist').read().splitlines()[4:] if self.process_name in self.item.split() ] if self.get_pid[0] == "": self.em = Emulator(visible=True) self.em.connect('prda.bcpcorp.net') else: print 'Program already open'
def mainframe_open_connection(): dap_log_mainframe(LogLevel.DEBUG, "connecting to mainframe") global em #em = Emulator(visible=True) em = Emulator() em.connect(MainframeIP) mainframe_random_wait( ) # this is necessary because mainframe response time can vary, the delay is worth it dap_log_compliance(LogLevel.INFO, "mainframe connection established") dap_log_mainframe(LogLevel.DEBUG, "selecting mainframe application") em.fill_field(20, 21, 'B', 1) em.send_enter() mainframe_random_wait()
def __init__(self, visible=True, timeout='30', wait_time='0.5', img_folder='.'): """You can change to hide the emulator screen set the argument visible=${False} For change the wait_time see `Change Wait Time`, to change the img_folder see the `Set Screenshot Folder` and to change the timeout see the `Change Timeout` keyword. """ self.lu = None self.host = None self.port = None self.credential = None self.imgfolder = img_folder self.output_folder = BuiltIn().get_variable_value('${OUTPUT DIR}') self.wait = float(wait_time) self.timeout = int(timeout) self.mf = Emulator(visible=bool(visible), timeout=int(timeout))
r'C:\Users\garren-james\Python Projects\UserID_Creation_Process\AMS_User_IDs.xlsx' ) ws1 = wb1['RACF User ID'] ws2 = wb1['Admins'] x = 1 y = input('Enter a number of records to process: ') y = int(y) rn = input('Enter row number to start from: ') rn = int(rn) now = datetime.now() today = now.strftime("%m%d%Y") currPwrd = 'dcfams03' newPwrd = 'dcfams04' while x <= y: em = Emulator(visible=False) em.connect('dcft.dcf.state.fl.us') usrId = 'A' + str(rn) usrId = ws1[usrId].value usrId = str(usrId) usrId = 'A' + usrId em.wait_for_field() em.send_string('flors2') em.send_enter() em.wait_for_field() em.fill_field(11, 36, usrId, 7) em.fill_field(12, 36, currPwrd, 8) em.fill_field(13, 61, newPwrd, 8) em.fill_field(14, 61, newPwrd, 8) em.send_enter() em.send_enter()
import time import string import itertools from py3270 import Emulator BOOKING_NUMBER_CHARSET = string.ascii_uppercase + string.digits em = Emulator(visible=True) #em.connect('nusse.seatheworld.tld') em.connect('127.0.0.1', 10023) def login(username, password): em.send_string("LOGON " + username) em.send_enter() em.send_string(password) em.send_enter() em.send_string("LOAD IBMUSER.SEATW.LOAD(BOOKING)") em.send_enter() em.send_enter() def check_booking_number(booking_number): em.send_string("1") em.send_enter() em.send_string(booking_number) em.send_enter() c = em.exec_command("Ascii") output = "\n".join([line.decode() for line in c.data]) if "FOUND 0 RECORDS" in output: return False print("=" * 64) return output
# # Sample 3270 screen scraping using py3270 library # import time import sys from py3270 import Emulator delayt = 1 # In sec, slowing down to be able to see the screen update mylogin = '******' mypass = '******' myhost = '192.168.1.100:3270' screenrows = [] # use x3270 so you can see what is going on my3270 = Emulator(visible=True) # or not (uses s3270) # my3270 = Emulator() try: # TSO login my3270.connect(myhost) my3270.wait_for_field() # my3270.send_clear() my3270.exec_command(b"Clear") my3270.wait_for_field() time.sleep(delayt) if not my3270.string_found(23, 1, 'Logon ===>'): sys.exit('Error: print(my3270.string_get(23,1,20))') my3270.send_string(mylogin) my3270.send_enter()
class Wrapper: # Atributos de la clase em = Emulator(visible=True) __mainframe = '155.210.152.51:103' timeout = 0.25 timeout_iniciar = 2.25 __grupo = 'grupo_04' __password = '******' ######################################################################################### # PRIVATE METHODS ######################################################################################### # PRIVATE: login es <=8 # si supera la longitud, la trunca def __loginTruncate(self, login): if len(login) > 8: login = login[0:7] return login # PRIVATE: obtener la fecha en formato ddmm def __fechasTruncate(self, date): lista_date = date.split('/') date = lista_date[0] + lista_date[1] return date # PRIVATE: descripcion es <=12 # si supera la longitud, la trunca def __descriptionTruncate(self, description): description = description.replace(" ", "_") if len(description) > 12: description = description[0:11] return description # PRIVATE: nombre es <=5 # si supera la longitud, la trunca def __nameTruncate(self, name): name = name.replace(" ", "_") if len(name) > 5: name = name[0:5] return name # PRIVATE: comprobar si abajo a la derecha aparece "More" # si True, aparece y pulsa enter def __isMore(self): m = self.em.string_get(43, 71, 4) if m == "More": self.em.send_enter() self.em.wait_for_field() time.sleep(self.timeout) # time.sleep(3) # PRIVATE: volver al menu principal def __mainMenu(self): self.__isMore() self.em.send_string('3', ypos=None, xpos=None) self.em.send_enter() self.em.wait_for_field() time.sleep(self.timeout) # PRIVATE: avanza a la operacion "Crear tarea" def __assignTask(self): self.__isMore() self.em.send_string('1', ypos=None, xpos=None) self.em.send_enter() self.em.wait_for_field() time.sleep(self.timeout) # PRIVATE: avanza a la operacion "Ver tarea" def __viewTask(self): self.__isMore() self.em.send_string('2', ypos=None, xpos=None) self.em.send_enter() self.em.wait_for_field() time.sleep(self.timeout) # PRIVATE: leer las tareas presentes en una pantalla # Nota: en caso de estar mostrando dos veces la lista en la # pantalla, se queda con la mas completa def __readTask(self, list, tipo): i = 1 while i < 41: # Compruebo si la linea es una tarea isTask = self.em.string_found(i, 1, 'TASK') if isTask: isTipo = self.em.string_found(i, 9, tipo) isTipo2 = self.em.string_found(i, 10, tipo) isTipo3 = self.em.string_found(i, 11, tipo) if isTipo or isTipo2 or isTipo3: newTask = self.em.string_get(i, 1, 80) if newTask in list: pass else: list.append(newTask) i = i + 1 time.sleep(self.timeout) return list # PRIVATE: devuelve la fecha pasada como "ddmm" en el formato "dd/mm" def __dateFormat(self, d): day = int(d) // 100 if day < 10: day = '0' + str(day) else: day = str(day) month = int(d) % 100 if month < 10: month = '0' + str(month) else: month = str(month) date = day + '/' + month return date # PRIVATE: convierte las tareas a lista de listas para devolver en # el formato acordado def __listOfLists(self, lista): result = list() for tarea in lista: contenido = tarea.split(' ') # Sustituyo en nombre y descripcion por _ por espacio contenido[5] = contenido[5].replace("_", " ") contenido[4] = contenido[4].replace("_", " ") # Nos quedamos con los campos que nos interesan de la linea info = contenido[3:6] print(info[0]) info[0] = self.__dateFormat(info[0]) print(info[0]) nTarea = contenido[1].split(':') nTarea = nTarea[0] newTarea = [nTarea] + info result.append(newTarea) return result # PRIVATE: probar el funcionamiento del wrapper # NOTA: no esta definido como metodo privado porque tenemos que usarlo # para testear el wrapper, pero no lo consideramos parte de la API def test(self): self.iniciar() buleano = self.login("grupo_04", "secreto7") print(buleano) buleano = self.login("grupo_04", "sesecto7") print(buleano) buleano = self.login("grupo_04", "LETS GO G2") print(buleano) buleano = self.login( "LECTRONICS", "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA") print(buleano) buleano = self.login("grupo_04", "secreto6") print(buleano) tarea = 0 while tarea < 5: self.generalTask("01/02/04", "Tarea " + str(tarea)) tarea = tarea + 1 # Medir tiempos t = time.time() self.generalTask("01/02/04", "GENERAL") t = time.time() - t print("NUEVA GENERAL: " + str(t)) t = time.time() r = self.viewGeneralTask() t = time.time() - t print("LISTAR GENERALES: " + str(t)) t = time.time() self.specificTask("01/10/04", "especifica", "soy prueba de especifica") t = time.time() - t print("NUEVA ESPECIFICA: " + str(t)) t = time.time() s = self.viewSpecificTask() t = time.time() - t print("LISTAR ESPECIFICAS: " + str(t)) print(r) print("------------------------------------") print(s) time.sleep(2) self.exitMainFrame() ######################################################################################### # PRIVATE METHODS ######################################################################################### # PUBLIC: iniciar la conexion con la maquina Mainframe def iniciar(self): self.em.connect(self.__mainframe) self.em.wait_for_field() self.em.send_enter() self.em.wait_for_field() time.sleep(self.timeout) #PUBLIC: # Intenta iniciar sesion # IN: grupo, password # OUT: booleano # False, si no hay logrado iniciarse la sesion # True , si ha iniciado sesion def login(self, grupo, password): grupo = self.__loginTruncate(grupo) password = self.__loginTruncate(password) logged = False self.em.fill_field(3, 18, grupo, 8) self.em.fill_field(5, 18, password, 8) self.em.send_enter() self.em.wait_for_field() time.sleep(self.timeout) for x in range(4, 8): contenido = self.em.string_get(x, 1, 26) if contenido == "Press ENTER to continue...": logged = True self.em.send_enter() self.em.wait_for_field() time.sleep(self.timeout) if logged: self.em.fill_field(3, 15, 'tareas.c', 8) self.em.send_enter() self.em.wait_for_field() time.sleep(self.timeout) # Necesario porque la ejecucion de tareas tarda un poco time.sleep(self.timeout_iniciar) else: self.em.send_enter() self.em.wait_for_field() time.sleep(self.timeout) return logged # PUBLIC: termina la ejecucion de tareas.c y vuelve al menu principal del # mainframe. # Si salimos -> perdemos las tareas almacenadas (no persistente) def exitMainFrame(self): self.__isMore() self.em.send_string('3', ypos=None, xpos=None) self.em.send_enter() self.em.wait_for_field() time.sleep(self.timeout) self.em.send_enter() self.em.wait_for_field() time.sleep(self.timeout) self.em.terminate() # PUBLIC: INTRODUCIR NUEVA TAREA GENERAL # IN: fecha, descripcion # OUT: nada def generalTask(self, date, description): date = self.__fechasTruncate(date) description = self.__descriptionTruncate(description) self.__assignTask() self.__isMore() self.em.send_string('1', ypos=None, xpos=None) self.em.send_enter() self.em.wait_for_field() time.sleep(self.timeout) self.__isMore() self.em.send_string(date, ypos=None, xpos=None) self.em.send_enter() self.em.wait_for_field() time.sleep(self.timeout) self.__isMore() self.em.send_string(description, ypos=None, xpos=None) self.em.send_enter() self.em.wait_for_field() time.sleep(self.timeout) self.__mainMenu() # PUBLIC: INTRODUCIR NUEVA TAREA ESPECIFICA # IN: fecha, nombre, descripcion # OUT: nada def specificTask(self, date, name, description): date = self.__fechasTruncate(date) description = self.__descriptionTruncate(description) name = self.__nameTruncate(name) self.__assignTask() self.__isMore() self.em.send_string('2', ypos=None, xpos=None) self.em.send_enter() self.em.wait_for_field() time.sleep(self.timeout) self.__isMore() self.em.send_string(date, ypos=None, xpos=None) self.em.send_enter() self.em.wait_for_field() time.sleep(self.timeout) self.__isMore() self.em.send_string(name, ypos=None, xpos=None) self.em.send_enter() self.em.wait_for_field() time.sleep(self.timeout) self.__isMore() self.em.send_string(description, ypos=None, xpos=None) self.em.send_enter() self.em.wait_for_field() time.sleep(self.timeout) self.__mainMenu() # PUBLIC: LISTAR TAREAS GENERALES # IN: sin argumentos # OUT: lista de listas. Cada componente una tarea. # [[nTarea1,fecha1,nombre1,des1],[nTarea2,fecha2,nombre2,des2]] # Nota: nombreX sera la cadena vacia porque las tareas # generales carecen de descripcion def viewGeneralTask(self): self.__viewTask() self.__isMore() self.em.send_string('1', ypos=None, xpos=None) self.em.send_enter() self.em.wait_for_field() time.sleep(self.timeout) tareas = list() # simulamos do while while True: tareas = self.__readTask(tareas, "GENERAL") more = self.em.string_get(43, 71, 4) if more != "More": break else: self.em.send_enter() self.em.wait_for_field() time.sleep(self.timeout) # Convertimos a lista de listas result = self.__listOfLists(tareas) self.__mainMenu() return result # PUBLIC: LISTAR TAREAS ESPECIFICAS # IN: sin argumentos # OUT: lista de listas. Cada componente una tarea. # [[nTarea1,fecha1,nombre1,des1],[nTarea2,fecha2,nombre2,des2]] def viewSpecificTask(self): self.__viewTask() self.__isMore() self.em.send_string('2', ypos=None, xpos=None) self.em.send_enter() self.em.wait_for_field() time.sleep(self.timeout) tareas = list() # simulamos do while while True: tareas = self.__readTask(tareas, "SPECIFIC") more = self.em.string_get(43, 71, 4) if more != "More": break else: self.em.send_enter() self.em.wait_for_field() time.sleep(self.timeout) # print(tareas) # Convertimos a lista de listas result = self.__listOfLists(tareas) self.__mainMenu() return result
def mock(cls, timeout=30): return Emulator(timeout=timeout, app=ExamApp())
import random import time from py3270 import Emulator from mainframe_credentials import MainframeIP, MainframeUsername, MainframePassword from dap_logging import dap_log_compliance, dap_log_mainframe, LogLevel em = Emulator() def mainframe_open_connection(): dap_log_mainframe(LogLevel.DEBUG, "connecting to mainframe") global em #em = Emulator(visible=True) em = Emulator() em.connect(MainframeIP) mainframe_random_wait( ) # this is necessary because mainframe response time can vary, the delay is worth it dap_log_compliance(LogLevel.INFO, "mainframe connection established") dap_log_mainframe(LogLevel.DEBUG, "selecting mainframe application") em.fill_field(20, 21, 'B', 1) em.send_enter() mainframe_random_wait() def mainframe_login(): dap_log_mainframe(LogLevel.DEBUG, "logging into mainframe")
def Open_3270(self, hostname): '''Opens emulator. Provide the hostname as argument''' self.em = Emulator(visible=True) self.em.connect(str(hostname))