示例#1
0
import numpy as np
import Image
import random
import time
import cprint
import sys

I = Image.open(sys.argv[1])
dim = I.size[0]
# print dim, I.size
Nz = I.size[1] / I.size[0]
arr = np.array(I).reshape((Nz, dim, dim))
N = dim
p = 0
cprint.cprint(p, Nz, N, arr)
示例#2
0
from cprint import cprint

cprint('R', 'red string.')
cprint('G', 'green string.')
cprint('Y', 'yellow string.')
cprint('B', 'blue string.')
cprint('P', 'purple string.')
cprint('C', 'green+ string.')

cprint('HR', 'highlight red string.')
cprint('HG', 'highlight green string.')
cprint('HY', 'highlight yellow string.')
cprint('HB', 'highlight blue string.')
cprint('HP', 'highlight purple string.')
cprint('HC', 'highlight green+ string.')
示例#3
0
    def run(self, unreg=True):
        print random.choice(self.asciiart)
        print '\n\n'
        cprint('\n[cyan][underline]Hypno-Shell. version 0.1[/][/]\n', colorize=colorize)
        if not self.commands_sets:
            cprint('[red]No registered commands[/]', colorize=colorize)
            cprint('To register set of commands use[blue] `reg`[/]', colorize=colorize)
            cprint('[blue]`help reg`[/] for more information\n', colorize=colorize)

        # cmd = ''
        while not self.exit:
            try:
                cmd = raw_input(cprint('[green]'+self.line+'[/]', colorize=colorize, noprint=True))
            except KeyboardInterrupt:
                cprint('\nPlease, enter [blue]`exit`[/] or [blue]`quit`[/]', colorize=colorize)
                continue
            # Empty
            if not cmd:
                continue

            parsed_cmd = _parse_command(cmd)
            
            commands = list()
            if parsed_cmd.set:
                if parsed_cmd.set in self.commands_sets:
                    commands.append(self.commands_sets[parsed_cmd.set].get_command(parsed_cmd.command))
                else:
                    cprint('[red]Cant find [blue]`%s`[/] in set [yellow]"%s"[/][/]' % (parsed_cmd.command, parsed_cmd.set), colorize=colorize)
            elif parsed_cmd.command in self.reserved_commands:
                commands.append(self.get_command(parsed_cmd.command))
            else:
                commands.append(self.get_command(parsed_cmd.command))
                for set_name, set_self in self.commands_sets.items():
                    commands.append(set_self.get_command(parsed_cmd.command))
            commands = filter(lambda x: x is not None, commands)

            if commands:
                if len(commands) > 1:
                    cprint('Found [blue]%s[/] commands. Use one from list below:' % len(commands), colorize=colorize)
                    for command in commands:
                        cprint('[yellow]$%s[/] [red]->[/] [blue]%s[/]' % (command.im_class.__name__, parsed_cmd.command), colorize=colorize)
                else:
                    commands[0](parsed_cmd.args) if parsed_cmd.args else commands[0]()
            else:
                cprint('[red]Command [blue]`%s`[/] does not exists![/]' % parsed_cmd.command, colorize=colorize)
        if unreg:
            self.unregister()
示例#4
0
文件: seg.py 项目: defland/jobstat
def print_txt(txt_list):

    cprint(txt_list)
示例#5
0
                if(np.sqrt((i-r/2)**2+(j-r/2)**2+(k-r/2)**2) < r):
                    s[i,j,k] = 1

def borderD(data):
    dfield = np.array(scipy.ndimage.distance_transform_edt(data)).reshape(dim,dim,Nz)
    return np.array(255*(dfield<0.1)).astype(np.uint8)

def border(data):
    r = 16
    r2 = 15
    r3 = 14
    r4 = 13
    c = scipy.ndimage.binary_closing(data,structure=np.ones((r,r,r))).astype(np.uint8)
    d = scipy.ndimage.binary_dilation(c,structure=struct(r2)).astype(np.uint8)
    e = scipy.ndimage.binary_erosion(d,structure=struct(r3)).astype(np.uint8)

    c = scipy.ndimage.binary_closing(d-e,structure=struct(r4)).astype(np.uint8)
    c = scipy.ndimage.binary_dilation(c,structure=struct(r4)).astype(np.uint8)
    return np.array(255*(c)).astype(np.uint8)

I = Image.open(sys.argv[1])
dim = I.size[0]
Nz = I.size[1]/I.size[0]
arr = np.array(I).reshape((Nz,dim,dim))
N = dim

p = 0

cprint.cprint(p,Nz,N,borderD(arr))

示例#6
0
def error(msg):
    cprint(f"[R]Quit: " + msg)
    input('Press enter to continue')
    exit()
示例#7
0
文件: seg.py 项目: defland/jobstat
def read_txt():

    pass
    return True


if __name__ == "__main__":

    txt = "职位描述: \n1、负责机器学习算法的线上布置和生产环境安全;\n2、负责数据计算平台的设计与研发;  \n3、负责数据计算平台的运营维护,推进标准化运维,提升运维质量。\n\n任职要求: \n1、本科以上学历计算机相关专业,有Python相关开发工作经验; \n2、熟悉MySQL数据库的使用与性能优化,熟悉NoSQL(Redis与MongoDB)者优先; \n3、熟悉MVC架构,精通Tornado、Django或Flask等web框架; \n4、熟悉Javascript / HTML / JSON / HTML5 / JQuery /CSS相关技术; \n5、有爬虫开发经验者优先; \n6、有机器学习算法开发经验者优先;\n7、有大数据系统(Hadoop、Hbase)经验者优先。"

    # print txt

    p = re.compile("\s")
    txt = p.sub('', txt)

    # print txt

    x = re.compile('\d')
    txt = x.sub('', txt)

    print txt

    print("关键词提取如下:")
    print_txt(keyword(txt))

    print("分词算法")
    x = seg(txt)
    cprint([i for i in x])

    pass
示例#8
0
    return folder if folder != '' else False


def check_dir(directory):
    return path.isdir(directory)


###############
#    SETUP    #
###############

steam_root = (environ["ProgramFiles(x86)"] + "/Steam").replace("\\", "/")

#Check root dir
if not check_dir(steam_root):
    cprint(f"[R]Steam directory not found. Please locate the steam folder")
    steam_root = ask_folder()
    if not steam_root: error("Please locate the Steam folder.")

cprint(f"[GR]Steam directory found. [G]({steam_root})")

#Check steamVR directory
steam_vr = steam_root + '/steamapps/common/SteamVR'
if not check_dir(steam_vr):
    cprint(
        f"[R]SteamVR not found at [G]{steam_vr}[R].\n\n[Y]Is SteamVR installed?"
    )

    #Ask user if installed
    if not input('(Yes or No): ').lower() in ['y', 'yes', 'ye']:
        error(f"Please install SteamVR before running this.")
示例#9
0
文件: demo.py 项目: Hell13Cat/cprint
from cprint import cprint

cprint("Text")

cprint("~{black:red:b}~Test b~{reset}~Reset text")

cprint("~{:red:}~Red text~{:green:}~Green text~{reset}~Normal text")
示例#10
0
         else:
             cprint.cprintln("Not Found", "mormal", "red")
         continue
     except:
         pass
 if cmd.startswith("list"):
     i = 1
     cmd = re.sub(r"\s+", " ", cmd)
     all_host = None
     if len(cmd.split(" ")) > 1:
         all_host = redis_helper.keys("HIDSHOST-{0}*".format(
             cmd.split(" ")[1]))
     else:
         all_host = redis_helper.keys("HIDSHOST-*")
     for h in all_host:
         cprint.cprint("{0}:".format(i), "mormal", "green")
         print(" {0}".format(h.split("-")[1]))
         i = i + 1
     if i == 1:
         cprint.cprintln("Not Found", "mormal", "red")
 elif cmd == "count":
     all_host = redis_helper.keys("HIDSHOST-*")
     cprint.cprint("Online Hosts: ", "mormal", "green")
     print("{0}".format(len(all_host)))
 elif cmd == "help":
     cprint.cprint("list: ", "mormal", "green")
     print("Show all hids online host.")
     cprint.cprint("count: ", "mormal", "green")
     print("Get onlion HIDS count.")
     cprint.cprint("some ip: ", "mormal", "green")
     print(
示例#11
0
def display_day03():
    '''
    Display day 03 in the story.
    '''
    clear_screen()
    # Blue text
    cprint("DAY 3", fg='b')
    cprint("===============", fg='b')
    # create random delay between 1 and 2 seconds
    time.sleep(random.randrange(1, 2))

    print("")
    print("You continue on walking through the forest. 🌲 🌲 🌲")
    time.sleep(random.randrange(1, 2))
    print("")
    print("Your mission is to find a stick so that you can make a fishing pole and finally eat! 🎣")
    time.sleep(random.randrange(2, 3))
    print("")
    print("You manage to find 🔍 a stick and put together a simple, although functional fishing pole. 😎")
    time.sleep(random.randrange(3, 4))
    print("")
    print("Luckily 🍀 you also come across a small lake")
    time.sleep(random.randrange(1, 2))
    print("")
    print("Now, about to faint due to lack of food, you sit down and begin fishing.")
    print("")
    time.sleep(random.randrange(2, 3))

    # Sun / lake with fish
    # sun copied from wego project https://github.com/schachmat/wego/blob/master/frontends/ascii-art-table.go
    # Note: the blinking text doesn't work on repl.it

    cprint("                            \\   /  ", fg='y')
    cprint("                             .-.    ", fg='y')
    cprint("                          ‒ (   ) ‒ ", fg='y')
    cprint("                             `-᾿    ", fg='y')
    cprint("                            /   \\  ", fg='y')
    cprint("                                    ")
    cprint(r"\🐟/\  /\  /\🐟/\  /\  /\🐟/\  /\  /", fg='b', style='x')
    cprint(r" \/  \/🐟\/  \/  \/🐟\/  \/  \/🐟\/ ", fg='b', style='x')
    time.sleep(4)
    clear_screen()

    # stop the blinking to avoid rage quit
    cprint("                            \\   /  ", fg='y')
    cprint("                             .-.    ", fg='y')
    cprint("                          ‒ (   ) ‒ ", fg='y')
    cprint("                             `-᾿    ", fg='y')
    cprint("                            /   \\  ", fg='y')
    cprint("                                    ")
    cprint(r"\🐟/\  /\  /\🐟/\  /\  /\🐟/\  /\  /", fg='b')
    cprint(r" \/  \/🐟\/  \/  \/🐟\/  \/  \/🐟\/ ", fg='b')

    print("")
    print("After waiting about 10 minutes 🕑 you feel a tug on the line.")
    time.sleep(random.randrange(2, 3))
    print("You caught a fish! Good job. 🏆")
    time.sleep(random.randrange(2, 3))

    print("")
    print("You cook the fish over a fire and feel satisfied. 🔥 🐟")
    time.sleep(random.randrange(2, 3))

    print("It's now almost night time. The sun begins to disappear into the horizon. 🌇")
    time.sleep(random.randrange(2, 3))
    print("")
    print("You have a decision to make:")
    time.sleep(random.randrange(1, 2))

    # Give the user a decision to make. Depending on their answer,
    # the game either ends here or they continue on to day 4
    question = '''\nWould you like to
    [1] Sleep on the lake shore under the stars. 🌃 ⛺
    [2] Go to the cave you see in the distance. That looks like a warm place to stay for the night. 👻
    \nType 1 or 2 and press ENTER to continue:\
    '''
    # Yellow text
    cprint(question, fg='y')
    answer = input()

    print("\n>> Your answer was: ", answer, "<<\n")

    if answer == "1":
        # Player decides to sleep on the lake shore and moves on to day 4.
        display_day04()
    else:
        # Player decides to go to the cave
        game_over_because("\nYour choice to sleep in a cave was not a wise one. You found a bear, and the bear found dinner. 🐻 \n")
示例#12
0
def display_day01():
    '''
    Display day 01 in story
    '''

    clear_screen()

    # Spaceship ASCII art
    # Add animation "effect" using
    # decreasing image width - see art.py file
    cprint(art.ASCII_SPACESHIP_01, fg='g')
    time.sleep(0.5)
    clear_screen()
    cprint(art.ASCII_SPACESHIP_02, fg='g')
    time.sleep(0.5)
    clear_screen()
    cprint(art.ASCII_SPACESHIP_01, fg='g')
    time.sleep(0.5)
    clear_screen()
    cprint(art.ASCII_SPACESHIP_02, fg='g')
    time.sleep(0.5)
    clear_screen()
    cprint(art.ASCII_SPACESHIP_03, fg='g')
    time.sleep(2)
    clear_screen()

    # Blue text
    cprint("DAY 1", fg='b')
    cprint("===============", fg='b')
    # create random delay between 1 and 2 seconds
    time.sleep(random.randrange(1, 2))

    print("")
    print("You wake up.")
    time.sleep(random.randrange(1, 2))
    print("Looking down at your watch, you notice that it's 8 AM. ⏰")
    print("...")
    time.sleep(random.randrange(1, 2))

    print("You are not sure where you are, 🗺")
    print("but you begin to remember a crash landing in your space vehicle,")
    print("")
    time.sleep(random.randrange(1, 2))
    print("🚀")
    time.sleep(random.randrange(1, 2))
    print("🌠")
    time.sleep(random.randrange(1, 2))
    print("🔥 🔥 🔥")
    time.sleep(random.randrange(1, 2))
    print("")
    print("which you now see approximately 20 feet behind you.")
    time.sleep(random.randrange(1, 2))

    # Get main character name (still day 01)
    # Add color: Yellow text for user input
    cprint("\nWhat was your name again?: ", fg='y')
    name = input()

    # Use str.title method to capitalize first letter of user name
    print("\nWell,", name.title(), ", you tell yourself...")
    print("It's time to figure out what's going on.")
    time.sleep(random.randrange(1, 2))

    # Give the user a decision to make. Depending on their answer,
    # the game either ends here or they continue on to day 2
    question = '''\nWould you like to
    [1] Go back to the spaceship to repair it 🛠  or
    [2] go explore the forest? 🌲 🌲 🌲
    \nType 1 or 2 and press ENTER to continue:\
    '''
    # Yellow text
    cprint(question, fg='y')
    answer = input()

    print("\n>> Your answer was: ", answer, "<<\n")

    if answer == "1":
        # Player is going back to the spaceship.. bad choice
        game_over_because("Your choice to go back to the spaceship was ultimately the wrong one.")
    else:
        # Player moves on to day 02
        display_day02()