Пример #1
0
def run():
    data = pd.read_csv('50_states.csv')
    states = data[data.columns[0]]
    print(states)
    screen = Screen()
    screen.title('U.S. States Game')
    image = "blank_states_img.gif"
    screen.addshape(image)
    turtle.shape(image)

    # def get_mouse_click_cords(x, y):
    #     print(x, y)
    # turtle.onscreenclick(get_mouse_click_cords)

    is_guessing = True
    counter = 0
    guessed_states = []

    while is_guessing:
        answer_state = screen.textinput(title=f"{counter}/50 Guess the State", prompt="What's another State name?").title().strip()
        if answer_state == "Exit":
            missing_states = [x for x in states if x not in guessed_states]
            print(f'The states that you missed guessing are:\n{missing_states}')
            # save a list with the missing states to learn:
            new_data = pd.DataFrame(missing_states)
            new_data.to_csv('states_to_learn.csv')
            break

        for st in data['state']:
            if st == answer_state:
                guessed_states.append(answer_state)
                counter += 1
                state_data = data[data.state == answer_state]   # Obtiene los datos de la fila
                state_cords = (int(state_data.x), int(state_data.y))
                print_state = Naming(st, state_cords)
            #     place_state(answer_state)
            if counter == 51:
                is_guessing = False
Пример #2
0
    async def create_containers(self, update):
        # Clean up all the containers
        if not update:
            await self.delete_containers()

        # Make sure the defined images are available and config the ports
        count, image_ports, unique_ports = await self.setup_images(
            self.config.images, update)

        addresses, subnet, gateway = self.get_available_address(
            self.config.network.hosts)

        # Do not recreate the network during an update. docker does not provide a
        # way to update the network so during an update it would need to be dropped and
        # updated. The network id for any existing containers would need to be updated
        if not update:
            # Create a network for the containers
            await self.create_network(self.config.network.hosts, subnet,
                                      gateway)

            # Apply the iptable rules required for the configured images
            rules = IPTableRules(self.config)
            rules.create(subnet, unique_ports)

        logging.info('Creating containers')

        # Create a unique list of host names
        naming = Naming()
        host_names = naming.generate_host_names(self.config.naming, count)

        scripts_dir = ''.join([os.getcwd(), SCRIPTS_DIR])
        logging.info('Using %s for script directory', scripts_dir)

        client = aiodocker.Docker()
        for image in self.config.images:

            # If the image has no exposed ports then there is no use in
            # creating a container
            if image.name not in image_ports:
                continue

            ports = [port.text for port in image_ports[image.name]]
            ports = dict.fromkeys(ports, {})
            for count in range(image.count):
                host_name = host_names.pop()
                ip = addresses.pop(0)
                mac = utility.Net.generate_mac(ip)
                config = {
                    'Hostname': host_name,
                    'Image': image.name,
                    'ExposedPorts': ports,
                    'MacAddress': mac,
                    'Env': image.env_variables,
                    'NetworkingConfig': {
                        'EndpointsConfig': {
                            'clab': {
                                'IPAMConfig': {
                                    'IPv4Address': ip,
                                },
                            }
                        }
                    }
                }

                if not image.startup_script is None and len(
                        image.startup_script) > 0:
                    config['HostConfig'] = {
                        'Binds': ['{}:{}'.format(scripts_dir, SCRIPTS_DIR)],
                    }

                logging.debug('Creating container %s:%s', host_name,
                              image.name)
                container = await client.containers.create(config,
                                                           name=host_name)

                # Persist the container info to the db with the ports
                # Ports are used to determine what listeners to create
                new_container = Container.create(
                    container_id=container.id,
                    name=host_name,
                    ip=ip,
                    mac=mac,
                    start_delay=image.start_delay,
                    start_retry_count=image.start_retry_count,
                    start_on_create=image.start_on_create,
                    sub_domain=image.sub_domain)

                # Some containers perform a lot of startup work when run for the first time
                # To mitigate this containers can be started and stopped on creation
                if image.start_on_create:
                    await self.start_container_on_create(
                        image, new_container, client)

                for port in image_ports[image.name]:
                    Port.create(container=new_container.id,
                                number=port.num,
                                protocol=port.protocol)

        await client.close()