16daystocode: How our bots work, plus other things

Ok, had to spend a little time.
So here is how I did that.

class AlgoStrategy(gamelib.AlgoCore):

    def __init__(self):
        super().__init__()
        random.seed()
        
        #added code
        self.install_and_import('requests')
        
        url = 'https://raw.githubusercontent.com/janis-s/external-terminal/master/say_hello.text'
        gamelib.debug_write('Hello, I can speak with the World. The World says: {}'
            .format(self.get_external_file(url)))

    def install_and_import(self, package):
        import importlib
        try:
            importlib.import_module(package)
        except ImportError:
            import pip
            self.install(package)
        finally:
            globals()[package] = importlib.import_module(package)

    def install(self, packge):
        subprocess.call([sys.executable, "-m", "pip", "install", package])

This resulted in:
/usr/local/lib/python3.7/dist-packages/urllib3/connectionpool.py:847: InsecureRequestWarning: Unverified HTTPS request is being made. Adding certificate verification is strongly advised. See: Advanced Usage - urllib3 2.2.4.dev24 documentation
InsecureRequestWarning)

Hello, I can speak with the World. The World says: Hello from outside :slight_smile:

2 Likes