diff --git a/.gitignore b/.gitignore index 8867cb1..f7c4fbf 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ __pycache__ chromedriver.exe chromedriver data.db +.envrc diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..0510189 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,40 @@ +# Use an official Python runtime as a parent image +FROM python:3.9-slim + +# Set environment variable to prevent Python from buffering its outputs +ENV PYTHONUNBUFFERED=1 + +# Set the working directory inside the container +WORKDIR /app + +# Copy the local requirements file to the container +COPY requirements.txt /app/requirements.txt + +# Install the required Python packages +RUN pip install --no-cache-dir -r requirements.txt + +# Install Selenium and its required drivers +RUN apt-get update && \ + apt-get install -y --no-install-recommends \ + wget \ + curl \ + unzip \ + chromium-driver \ + && apt-get clean \ + && rm -rf /var/lib/apt/lists/* + +# Set up Chrome WebDriver for Selenium +RUN wget -q -O /app/chromedriver.zip https://chromedriver.storage.googleapis.com/114.0.5735.90/chromedriver_linux64.zip && \ + unzip /app/chromedriver.zip && \ + chmod +x /app/chromedriver && \ + rm /app/chromedriver.zip + +# Set environment variables for Chrome and ChromeDriver +ENV PATH=/app:$PATH +ENV DISPLAY=:99 + +# Copy the rest of the application code to the container +COPY . /app + +# Start the bot +CMD ["python", "main.py"] diff --git a/config.py b/config.py index 8e365c5..a7cc381 100644 --- a/config.py +++ b/config.py @@ -2,5 +2,7 @@ import os TELEGRAM_TOKEN = os.environ.get("SECRETARX_TG_TOKEN", None) DB_PATH = "data.db" +CHROMEDRIVER_PATH = "chromedriver" + assert TELEGRAM_TOKEN diff --git a/requirements.txt b/requirements.txt index f3dc66a..6744be6 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,4 @@ pysqlite3 -selenium -requests -telebot +selenium==4.24.0 +requests==2.32.3 +telebot==0.0.5 diff --git a/xclient.py b/xclient.py index 8520bec..9b67bb0 100644 --- a/xclient.py +++ b/xclient.py @@ -6,6 +6,8 @@ from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support import expected_conditions as EC import time import requests +import config +from selenium.webdriver.chrome.service import Service class XClient: @@ -27,7 +29,10 @@ class XClient: # Set up the WebDriver (make sure to use the correct path for your WebDriver) options = webdriver.ChromeOptions() options.add_argument("--headless=new") - driver = webdriver.Chrome(options=options) + + service = Service(executable_path=config.CHROMEDRIVER_PATH) + + driver = webdriver.Chrome(options=options, service=service) driver.get("https://x.tudelft.nl")