def check_script(): db = MySQLdb.connect(host=db_host, user=db_user, passwd=db_password, db=db_name) cur = db.cursor() # placed here so that cur is initialized in case of KeyboardError em = Emulator() em.connect("bcvmcms.bc.edu") em.wait_for_field() em.fill_field(7, 46, uis_username, 9) em.fill_field(9, 46, uis_password, 15) em.send_enter() # em.fill_field(6, 44, '7', 4) #This is commented out for when BC changes the register page # em.send_enter() # em.fill_field(17, 34, '2', 1) # em.send_enter() em.fill_field(16, 22, "c", 1) em.send_enter() cur.execute("select * from checker_class") for row in cur.fetchall(): try: # print(row[1][:8]) # print(row[1][8:]) em.fill_field(3, 24, "", 8) em.send_enter() em.fill_field(3, 24, row[1][:8], 8) em.send_enter() sleep(0.09) if not em.string_found(8, 19, "No Courses"): class_found = False i = 0 page_turn = (int(row[1][8:]) - 1) / 16 while page_turn != 0: em.send_enter() page_turn = page_turn - 1 while class_found == False: if em.string_found(8 + i, 15, row[1][8:]): if em.string_found(8 + i, 68, "*CLOSED"): print row[1], " is closed" class_found = True break elif em.string_found(8 + i, 68, "*CANCEL"): print row[1], " is cancelled" class_found = True break else: print row[1], " is open" cur.execute( "select * from cc.checker_class_students c, cc.checker_student s where class_id = " + str(row[0]) + " and student_id = s.id" ) notify_thread = threading.Thread(target=notify_students, args=(cur.fetchall(), row)) notify_thread.start() cur.execute("delete from cc.checker_class_students where class_id = " + str(row[0])) cur.execute("delete from cc.checker_class where id = " + str(row[0])) class_found = True break i += 1 else: print ("class not found") except Exception as e: print (e) continue # closing time cur.close() db.commit() em.fill_field(3, 24, "QUIT", 8) em.send_enter() em.fill_field(16, 22, "l", 1) em.send_enter() em.terminate() sleep(300)
em.fill_field(23, 13, 'CLSM', 4) admin = 'C' + str(rn) admin = ws2[admin].value admin = str(admin) unit = admin dist = 'B' + str(rn) dist = ws2[dist].value dist = str(dist) newId = 'A' + str(rn) newId = ws2[newId].value newId = str(newId) em.fill_field(23, 29, admin + '/' + unit + '/' + dist, 14) em.send_enter() #Update the screen, when correctly loaded if (em.string_found(1, 2, 'CLSM') == True): em.fill_field(11, 12, 'AMS STRESS UNIT', 15) wrkNum = newId[-4:] wrkNum = int(wrkNum) + 1 wrkNum = str(wrkNum) if (len(wrkNum) == 3): wrkNum = '0' + wrkNum elif (len(wrkNum) == 2): wrkNum = '00' + wrkNum elif (len(wrkNum) == 1): wrkNum = '000' + wrkNum else: pass em.fill_field(11, 33, 'MS' + wrkNum, 6) em.fill_field(11, 68, today, 8) #select correct Service Site info based on Dist, would need to expand for more utility.
# 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() my3270.wait_for_field() time.sleep(delayt) if not my3270.string_found(1, 2, 'ENTER CURRENT'): sys.exit('Error: print(my3270.string_get(1, 2,20))') my3270.send_string(mypass) my3270.send_enter() my3270.wait_for_field() time.sleep(delayt) # if not my3270.string_found(13, 2, '***'): # sys.exit('Error: print(my3270.string_get(13,2,10))') my3270.send_enter() my3270.wait_for_field()
class Automation3270(object): '''Library for x3270 emulator automation. More information at http://x3270.bgp.nu/''' ROBOT_LIBRARY_SCOPE = 'GLOBAL' def Open_3270(self, hostname): '''Opens emulator. Provide the hostname as argument''' self.em = Emulator(visible=True) self.em.connect(str(hostname)) 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 Close_3270(self): '''Closes emulator''' self.pid_proc = 'wc3270.exe' self.pid = [ self.item.split()[1] for self.item in os.popen('tasklist').read().splitlines()[4:] if self.pid_proc in self.item.split() ] print "PID number is " + self.pid[0] os.kill(int(self.pid[0]), signal.SIGTERM) def Input_Text_on_Field(self, xpos, ypos, text): '''Writes text on field. Last parameters requires the lenght of the word''' self.em.fill_field(int(xpos), int(ypos), str(text), len(text) + 2) def Send_String(self, text, xpos, ypos): '''Verifies if a given string exists''' self.em.string_found(text, int(xpos), int(ypos)) def Keyboard_State(self): '''If the keyboard is unlocked, the letter U. If the keyboard is locked waiting for a response from the host, or if not connected to a host, the letter L''' print self.em.status.keyboard.capitalize() def wait_For_Field(self): '''Waits for execution''' self.em.wait_for_field() def Execute_Command(self, command): '''Executes custom commands. See more a thttp://x3270.bgp.nu/x3270-script.html''' self.em.exec_command(self, command) def Connection_State(self): '''If connected to a host, the string C(hostname). Otherwise, the letter N''' print self.em.status.connection_state.capitalize() def Get_String(self, xpos, ypos, lenght): '''Get String based on coordinates and lenght''' get_text = self.em.string_get(int(xpos), int(ypos), int(lenght)) return get_text def Press_Enter(self): '''Presses Enter key''' self.em.send_enter() def Move_cursor(self, xpos, ypos): '''Moves cursor to specified coordinates''' self.em.move_to(xpos, ypos) def Take_Screenshot(self): '''Takes printscreen''' self.em.save_screen() def Pause_Test(self): '''Pauses Test at a given moment''' self.em.app.readline() def Send_F3(self): '''Simulates F3 key''' self.em.send_pf3() def Send_F4(self): '''Simulates F4 key''' self.em.send_pf4() def Send_F5(self): '''Simulates F5 key''' self.em.send_pf5() def Send_F6(self): '''Simulates F6 key''' self.em.send_pf6() def Send_F7(self): '''Simulates F7 key''' self.em.send_pf7() def Send_F8(self): '''Simulates F8 key''' self.em.send_pf8()