def render_noose(count=0): noose = " " head = " " left_arm = " " torso = " " right_arm = " " left_leg = " " right_left = " " if count > 0: noose = "|" if count > 1: head = magenta("0") if count > 2: left_arm = yellow("/") if count > 3: torso = yellow("|") if count > 4: right_arm = yellow("\\") if count > 5: left_leg = cyan("/") if count > 6: right_left = cyan("\\") head = magenta("X") top_row = " +---+" noose_row = str.format("\n %s |" % noose) head_row = str.format("\n %s |" % head) torso_row = str.format("\n %s%s%s |" % (left_arm, torso, right_arm)) leg_row = str.format("\n %s %s |" % (left_leg, right_left)) bottom_row = "\n |\n==========\n" print(top_row + noose_row + head_row + torso_row + leg_row + bottom_row)
def __newestpick(self): ''' returns the newest file in the current list of files that was not played before. ''' log.info("*** choosing latest from %d files (%d played = %4.1f%%)", len(self.files), len(self.recentlist), 100. * len(self.recentlist) / len(self.files)) def fage(filename): try: sr = os.stat(filename) return time.time() - sr.st_ctime except OSError as e: return 999999999 unplayed = [f for f in self.files if not f in self.recentlist] if len(unplayed) < 1: log.warning( color.magenta( "no file found that is not in the recentlist! shifting out oldest entries..." )) assert len(self.recentlist ) > 0, "can not remove entries from empty recentlist" self.recentlist = self.recentlist[ max(len(self.recentlist) / 10, 1):] unplayed = [f for f in self.files if not f in self.recentlist] latest_file = sorted(unplayed, key=fage)[0] age = fage(latest_file) log.debug("latest file is %s (age %d sec)", latest_file, age) if age > 600: # switch to random mode if newest file is older than 10 min log.info( color.magenta( "newest file is %d sec old. switching to random mode." % age)) self.pick = self.__randompick return self.pick() return latest_file
def main(): parser = argparse.ArgumentParser( description='Scan n images to png and make a gif with them.') parser.add_argument('n', type=int, help='number of elements in the sequence') parser.add_argument('name', help='name of the sequence') parser.add_argument('--width', '-W', type=int, default=DEFAULT_WIDTH, help='width of the scanning area (in mm)') parser.add_argument('--height', '-H', type=int, default=DEFAULT_HEIGHT, help='height of the scanning area (in mm)') parser.add_argument('--delay', '-d', type=int, default=DEFAULT_DELAY, help='delay between images (in ms)') parser.add_argument('--resolution', '-r', type=int, default=DEFAULT_RESOLUTION, help='scanning resolution (in dpi)') parser.add_argument('--rotate', '-R', type=int, default=DEFAULT_ROTATION, help='rotate (in degrees)') args = vars(parser.parse_args()) # Make PNG from scan png_list = [] for i in range(args['n']): fi_name = '{}-{}.png'.format(args["name"], i) png_list.append(fi_name) with open(fi_name, 'wb') as fi: subprocess.call(scan_cmd.format(**args), shell=True, stdout=fi) print(yellow(fi_name)) # Make GIF from PNG inp = ' '.join(png_list) out = '{}.gif'.format(args["name"]) subprocess.call(gif_cmd.format(**args, input_files=inp, output_file=out), shell=True) print(magenta(out))
def client(): """ osc-client is a really simple interactive UDP client to send OSC messages. """ print_title('osc-client') client = pythonosc.udp_client.SimpleUDPClient(*_get_server_address()) print('Let\'s send messages !') path = '' value = [] while 1: print('Enter the path and the value of the requests.') path = minput('path', path) while 1: v = input(magenta('value [leave blank to send] >')) if v: value.append(v) else: break print('Sending: {} {} to {}:{}'.format(path, value, address, port)) client.send_message(path, value)
max_hits = 5 clients = 3 req = { 'trans': clients * max_hits, 'success': 0, 'fail': 0, 'time': 0, 'size': 0, 'long': '0', 'short': '0' } # Check for valid url try: r = requests.get(url) print(color.magenta('STARTING SERVER BENCHMARKING')) print(color.magenta('URL:\t\t', url)) print(color.magenta('Clients:\t', clients)) print(color.magenta('Requests:\t', max_hits, '\n')) time.sleep(1) except: print(color.red('Bad url, stopping')) sys.exit(1) print(color.yellow('** Cattle of Geryon 2.0')) print(color.yellow('** Preparing 1 concurrent users for battle.')) print(color.yellow('The server is now under siege...')) # Start benchmark i = 0
import color, time from pygame import mixer, event mixer.init() mixer.music.load('piao.mp3') mixer.music.play() print(color.magenta('-=' * 20)) print(color.yellow(' \033[1mÉ MAIOR, MENOR OU IGUAL?\33[m')) print(color.magenta('-=' * 20)) num1 = int(input(color.green('>DIGITE UM NÚMERO INTEIRO: '))) num2 = int(input(color.blue('>DIGITE OUTRO NÚMERO INTEIRO: '))) print(color.magenta('-=' * 20)) print(color.blue('PROCESSANDO A BAGAÇA...')) time.sleep(3) print(color.magenta('-=' * 20)) if num1 > num2: print('>O NÚMERO {} É MAIOR QUE O NÚMERO {}'.format(num1, num2)) elif num2 > num1: print('>O NÚMERO {} É MAIOR QUE O NÚMERO {}'.format(num2, num1)) else: mixer.music.load('naodeu.mp3') mixer.music.play() print('\033[1;31m>NÃO EXISTE VALOR MAIOR, OS DOIS SÃO IGUAIS.\033[m') print(color.magenta('-=' * 20)) time.sleep(7)
DEFAULT_IP = 'localhost' DEFAULT_PORT = 4242 parser = argparse.ArgumentParser() parser.add_argument('--ip-address', '-a', type=str, help='IP address of the OSC server.') parser.add_argument('--port', '-p', type=int, help='UDP port of the OSC server.') # This function is used to get a pretty input with default value. minput = lambda s, d: input(magenta('{} [{}] >'.format(s, d))) or d # This function is used to display the tool's name. print_title = lambda s: print('\n{}\n{}\n'.format(s, len(s) * '-')) def _get_server_address(): """ Return the server address and port in a tuple. Check if they was passed as arguments, or prompt for them. """ args = parser.parse_args() return (args.ip_address or minput('server adress', DEFAULT_IP), args.port or int(minput('ssrver port', DEFAULT_PORT)))