watchlist management

This commit is contained in:
Yigit Colakoglu 2024-09-10 14:11:50 +02:00
parent 259426df93
commit 77bfbe5113
5 changed files with 52 additions and 4 deletions

1
.gitignore vendored
View File

@ -5,3 +5,4 @@ __pycache__
chromedriver.exe chromedriver.exe
chromedriver chromedriver
data.db data.db
.envrc

40
Dockerfile Normal file
View File

@ -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"]

View File

@ -2,5 +2,7 @@ import os
TELEGRAM_TOKEN = os.environ.get("SECRETARX_TG_TOKEN", None) TELEGRAM_TOKEN = os.environ.get("SECRETARX_TG_TOKEN", None)
DB_PATH = "data.db" DB_PATH = "data.db"
CHROMEDRIVER_PATH = "chromedriver"
assert TELEGRAM_TOKEN assert TELEGRAM_TOKEN

View File

@ -1,4 +1,4 @@
pysqlite3 pysqlite3
selenium selenium==4.24.0
requests requests==2.32.3
telebot telebot==0.0.5

View File

@ -6,6 +6,8 @@ from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC from selenium.webdriver.support import expected_conditions as EC
import time import time
import requests import requests
import config
from selenium.webdriver.chrome.service import Service
class XClient: class XClient:
@ -27,7 +29,10 @@ class XClient:
# Set up the WebDriver (make sure to use the correct path for your WebDriver) # Set up the WebDriver (make sure to use the correct path for your WebDriver)
options = webdriver.ChromeOptions() options = webdriver.ChromeOptions()
options.add_argument("--headless=new") 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") driver.get("https://x.tudelft.nl")