def main(): """ Consists of the main functionality of the script. """ # Set variables clear = lambda: os.system('cls') m, e, f = Menu(), Extraction(), FileManage() # Create directory if doesn't exist data_folder = f.check_directory() html_filenames = f.get_html_filenames(data_folder) # Get the CSV file name clear() print("Input the name of the CSV file you want to create.") csv = m.get_filename() # Get the HTML file to extract data from clear() print("Select the index of the HTML file to extract data from.") html_opts = m.display_menu(html_filenames) sel_html = 'data/' + m.get_num_user_input(html_opts) # Select information to extract print("Select the index of the tag type you want to extract data from.") tag_list = ['Paragraphs', 'Headings', 'Links', 'Img urls', 'All text (no links)', 'All links', 'All content'] tag_opts = m.display_menu(tag_list) sel_tag = m.get_num_user_input(tag_opts) # Get contents of HTML and adds to CSV file e.get_content(sel_html, sel_tag, csv)
def main(): """ Consists of the main functionality of the script. """ # Create menu class m = Menu() # Display the main menu m.main_menu() # Run the program while (True): m.get_command()
def main(): """ Consists of the main functionality of the script. """ # Set variables option_list = ['Angle', 'Frequency', 'Length', 'Temperature', 'Volume', 'Weight'] m = Menu() # Run the menu conversion_type = m.type_list(option_list) # Conversion type convert_from, convert_to = m.convert_list(conversion_type) num = m.get_value(convert_from, convert_to) # Run the calculations c = Calculations(num) data = c.read_csv('utils/formulas.csv') c.run_conversion(data, convert_from, convert_to)
def main(): """ Consists of the main functionality of the script. """ m, e = Menu(), Editor() clear = lambda: os.system('cls') # Set command list command_list = [ 'info', 'display', 'create', 'add', 'remove', 'update', 'exit' ] commands = [("info", m.main_menu), ("display", e.display_data), ("create", e.create_file), ("add", e.add_data), ("remove", e.remove_data), ("update", e.update_data), ("exit", m.exit_program)] # Display menu clear() m.main_menu([]) # Get the users input while True: # Ask for user input, args as follows: 0, 1 = ['command', 'filename'] user_input = input("=> ").lower().split(" ") clear() # Error handle if only one argument if len(user_input) < 2: filename = '' else: filename = f'{user_input[1]}.csv' # Loop through each command for command in commands: # Run function based on command if user_input[0] == command[0]: command[1](filename) # Error if invalid command if user_input[0] not in command_list: print("Invalid command. Type 'info' for a list of commands => ")
def __init__(self): self.menu = Menu() self.view = HomeMenuView(self.menu)
def main(): global proxy_client, proxy_server LOG_FORMAT = "%(asctime)s - %(levelname)s - %(message)s" log_filename = 'logs/test_' + time.strftime("%Y%m%d", time.localtime()) + '.log' logging.basicConfig(filename=log_filename, level=logging.INFO, format=LOG_FORMAT) # 当前脚本所在目录路径 path = os.path.dirname(os.path.realpath(__file__)) test_config = TestConfig(path) if len(sys.argv) > 1: report_name = sys.argv[1] if 'ls' == sys.argv[1]: files = getFileName(path + '/config/') print(Util.pretty(files)) return else: report_name = 'default' # 获取测试用例数据 config = test_config.get_test_case(sys.argv) # 是否开启代理 is_open_proxy = config.get('BROWSER').get('proxy') if is_open_proxy: from browsermobproxy import Server bmp_path = config.get('BROWSER').get('bmp_path') logging.info('开启代理 ' + bmp_path) proxy_server = Server(bmp_path) proxy_server.start() proxy_client = proxy_server.create_proxy() # 浏览器类型 browser_type = config.get('BROWSER').get('type') # 是否使用H5测试,并指定移动设备名称 h5 = config.get('BROWSER').get('H5', False) device_name = config.get('BROWSER').get('device_name', 'iPhone 7') # 是否开启无头模式 headless = config.get('BROWSER').get('headless', False) if browser_type == 'Firefox': options = FirefoxOptions() if headless: options.add_argument("-headless") options.page_load_strategy = 'normal' if h5: user_agent = "Mozilla/5.0 (iPhone; U; CPU iPhone OS 3_0 like Mac OS X; en-us) AppleWebKit/528.18 (KHTML, like Gecko) Version/4.0 Mobile/7A341 Safari/528.16" options.set_preference("general.useragent.override", user_agent) if is_open_proxy: options.add_argument('--proxy-server={0}'.format( proxy_client.proxy)) browser = webdriver.Firefox(options=options) elif browser_type == 'Chrome': options = ChromeOptions() if headless: options.add_argument("--window-size=1920,1080") # 设置浏览器分辨率(窗口大小) options.add_argument( "--start-maximized") # 最大化运行(全屏窗口),不设置,获取元素可能会报错 options.add_argument("--disable-extensions") options.add_argument('--no-sandbox') # 取消沙盒模式,浏览器的安全性会降低 # 禁用GPU加速,降低资源损耗,only for Windows but not a valid configuration for Linux OS options.add_argument('--disable-gpu') options.add_argument('--disable-dev-shm-usage') # 解决资源有限的问题 options.add_argument('--lang=en_US') options.add_argument("--headless") options.page_load_strategy = 'normal' if h5: mobileEmulation = {'deviceName': device_name} options.add_experimental_option('mobileEmulation', mobileEmulation) if is_open_proxy: options.add_argument('--proxy-server={0}'.format( proxy_client.proxy)) browser = webdriver.Chrome(options=options) else: print('浏览器' + browser_type + ':类型不支持') return False logging.info('开始使用 ' + browser_type + ' 浏览器进行自动化测试') if is_open_proxy: proxy_client.new_har("req", options={ 'captureHeaders': True, 'captureContent': True }) if browser_type == 'Firefox' and h5: browser.set_window_size(360, 640) else: browser.maximize_window() # 浏览器等待时间 # browser.implicitly_wait(10) url = config.get('WEBSITE').get('url') browser.get(url) if is_open_proxy: Http.logHar(proxy_client.har) # 执行配置的TEST对象 test = config.get('TEST') suite = unittest.TestSuite() m = Menu() for key in test: menus = m.getMenuConfig(config, key) try: if is_open_proxy: test_data = [browser, menus, proxy_client] else: test_data = [browser, menus] suite.addTest( ParametrizedTestCase.parametrize(Action, 'test_menu', param=test_data)) except AssertExcetion: print(key + " 断言失败") # 是否生成报告,默认开启调试模式,不生成报告 debug = config.get('DEBUG', True) if debug: runner = unittest.TextTestRunner() runner.run(suite) else: # 报告是否含有截图,DEBUG为False且IMAGE设置为True时生效 image = config.get('IMAGE', False) report_path = path + '/reports/' report_file = report_name + "_" + time.strftime( "%Y%m%d", time.localtime()) + '.html' fp = open(report_path + report_file, 'wb') report_title = '你的测试报告' report_desc = '使用配置:' + report_name + '生成的测试报告' runner = HTMLTestRunner(stream=fp, verbosity=2, images=image, title=report_title, description=report_desc, tester='pystest') runner.run(suite) fp.close() sleep(5) browser.quit() # send mail or not mail = config.get('MAIL') if not debug and mail and mail.get('SEND'): email_title = report_title email_content = report_desc smtp = Mail(config.get('MAIL'), report_path) smtp.connect() smtp.login() smtp.send(email_title, email_content, report_file) smtp.quit() if is_open_proxy: proxy_client.close() proxy_server.stop()
def main(): utime.sleep_ms(1000) ############################################################################## # CREATE COMPONENTS logger.info("uname", uos.uname()) led_red = LED(1) # red led led_red.off() screen = Screen( spi=DynamicSPI( baudrate=54000000, pin_cs=Pin.board.P3, polarity=0, phase=0, ), alloc_screen_buff=True, width=320, height=240, pin_dc=Pin.board.P9, framebuffer_swap_endianness=True, fast_byteswap=False, ) control = Control(logger=logger) thermal = Thermal(logger=logger) # SPI at 40000000 or start_delay=100 would lead to data corruption camera_slave = CameraSlave( spi=DynamicSPI( baudrate=30000000, pin_cs=Pin.board.P4, polarity=0, phase=0, start_delay=500, ), pin_data_ready=Pin.board.P5, width=screen.width, height=screen.height, alloc_rx_buff=True ) touch = Touch( spi=DynamicSPI( baudrate=2000000, pin_cs=Pin.board.P7, polarity=0, phase=0, start_delay=10, byte_delay=10, ) ) auxiliary_controller = AuxiliaryController( spi=DynamicSPI( baudrate=2500000, pin_cs=Pin.board.P6, polarity=1, phase=0, start_delay=10, byte_delay=100, ) ) menu = Menu() settings = Settings("camera.json") time_settings = Settings("time.json") input_handler = InterruptHandler( pin_interrupt=Pin.board.P8, trigger=ExtInt.IRQ_FALLING ) components = { "logger": logger, "auxiliary_controller": auxiliary_controller, "touch": touch, "control": control, "thermal": thermal, "menu": menu, "screen": screen, "settings": settings, "time_settings": time_settings, "input_handler": input_handler, "camera_slave": camera_slave, } #testing_bug3(**components) ########################### DynamicSPI._verbose = False auxiliary_controller._verbose = False ############################################################################## # INITIALIZE COMPONENTS logger.info("Loading menu...") load_menu(components) logger.info("Initializing screen...") screen.initialize() screen.set_window(0, 0, screen.width, screen.height) screen.screen_buff.draw_rectangle(0, 0, screen.width, screen.height, color=(30,30,30), fill=True) screen.write_to_screen(screen.screen_buff) utime.sleep_ms(100) display_intro = False try: image.Image(control.startup_img_name, copy_to_fb=screen.screen_buff) display_intro = True except Exception as e: logger.info("Could not display startup image {}".format(e)) if display_intro: logger.info("Displaying intro") screen.screen_buff.draw_rectangle(0, 0, screen.width, 20, color=(30,30,30), fill=True) screen.screen_buff.draw_string(10,0, """Shutter Button is "Back" button""", color=(0,200,30), scale=2.0, mono_space=False) screen.screen_buff.draw_rectangle(0, round(screen.height*3/4), screen.width, round(screen.height*4/4), color=(30,30,30), fill=True) startup_text = "by JONATAN ASENSIO PALAO. v" + camera_version screen.screen_buff.draw_string(round(screen.width/11), round(screen.height*3.1/4), startup_text, color=(0,200,30), scale=2.0, mono_space=False) screen.screen_buff.draw_string(round(screen.width/11), round(screen.height*3.6/4), "LOADING... WAIT", color=(200,0,0), scale=2.0, mono_space=False) screen.write_to_screen(screen.screen_buff) logger.info("Initializing auxiliar processor...") if auxiliary_controller.initialize(timeout_ms=5000): logger.info("Initializtion complete. Last package number: ", auxiliary_controller.number_package_received()) else: screen.screen_buff.draw_rectangle(0, 0, screen.width, screen.height, color=(30,30,30), fill=True) screen.screen_buff.draw_string(10,0, "Aux processor error", color=(255,0,0), scale=2.0, mono_space=False) screen.write_to_screen(screen.screen_buff) utime.sleep_ms(10000) control.battery_millivolts = auxiliary_controller.battery_millivolts absolute_seconds = auxiliary_controller.time() logger.info("Battery:", control.battery_millivolts, "mV", " Absolute seconds:", absolute_seconds) logger.info("Initializing time...") sync_time(logger, screen, time_settings, auxiliary_controller) logger.info("Loading settings...") load_camera_slave_calibration_settings(settings=settings, camera_slave=camera_slave) load_touch_calibration_settings(settings=settings, touch=touch) load_control_settings(settings=settings, control=control) load_thermal_settings(settings=settings, thermal=thermal) logger.info("Initializing thermal camera...") thermal.initialize() logger.info("Enabling input interrupts...") input_handler.enable( callback=input_interrupt, **components ) logger.info("Running main loop...") loop(**components)
def initMenu(self): self.menu = Menu(self, self.menuData()) self.initApplySign()