Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Connect to an already running Nitter instance #4

Closed
pluja opened this issue Oct 20, 2021 · 1 comment
Closed

Connect to an already running Nitter instance #4

pluja opened this issue Oct 20, 2021 · 1 comment

Comments

@pluja
Copy link

pluja commented Oct 20, 2021

Would it be possible to use this connecting to an already running Nitter instance?

@pluja
Copy link
Author

pluja commented Oct 20, 2021

I solved this.

I added a new variable (container_name) to nitter.py file:

    host: IPv4Address
    port: int
    container_name: str

I added this function to my nitter.py file:

def get(self):
        client = self._get_client()
        self.container = client.containers.get(
            container_id=self.container_name
        )
        logger.info(f"Got container {self.container.name} {self.container.short_id}. Status {self.container.status} at {self.address}.")

And the context manager looks like this:

@contextmanager
def NitterScraper(host: str = "0.0.0.0", port: int = 8008, container_name: str = "ff1fc8e9f922"):
    """The NitterScraper context manager.

    Takes care of configuring, starting, and stopping a docker instance of nitter.

    Args:
        host: The host address the docker container will bind too.
        port: The port the docker container will listen to.
        container_name: The name or id of the container to connect.

    Yields:
        Nitter: An object representing a started nitter docker container.
    """
    nitter = Nitter(host=host, port=port, container_name=container_name)
    nitter.get()
    yield nitter

@pluja pluja closed this as completed Oct 20, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant