def capture(config): path = config['path'].get() workflow = Workflow(config=config, path=path) if len(workflow.devices) != 2: raise DeviceException("Please connect and turn on two" " pre-configured devices! ({0} were" " found)".format(len(workflow.devices))) print(colorize("Found {0} devices!".format(len(workflow.devices)), colorama.Fore.GREEN)) if any(not x.target_page for x in workflow.devices): raise DeviceException("At least one of the devices has not been" " properly configured, please re-run the" " program with the \'configure\' option!") # Set up for capturing print("Setting up devices for capturing.") workflow.prepare_capture() # Start capture loop shot_count = 0 pages_per_hour = 0 capture_keys = workflow.config['capture']['capture_keys'].as_str_seq() print("({0}) capture | (r) retake last shot | (f) finish " .format("/".join(capture_keys))) while True: retake = False char = getch().lower() if char == 'f': break elif char == 'r': retake = True elif char not in capture_keys: continue workflow.capture(retake=retake) shot_count += len(workflow.devices) pages_per_hour = (3600/(time.time() - workflow.capture_start))*shot_count status = ("\rShot {0: >3} pages [{1: >4.0f}/h] " .format(unicode(shot_count), pages_per_hour)) sys.stdout.write(status) sys.stdout.flush() workflow.finish_capture() if workflow.capture_start is None: return sys.stdout.write("\rShot {0} pages in {1:.1f} minutes, average speed was" " {2:.0f} pages per hour\n" .format(colorize(str(shot_count), colorama.Fore.GREEN), (time.time() - workflow.capture_start)/60, pages_per_hour)) sys.stdout.flush()