Fix dockerfile, switch to firefox
This commit is contained in:
parent
10fb02c90d
commit
083ea29c21
@ -19,20 +19,13 @@ RUN apt-get update && \
|
||||
build-essential \
|
||||
libsqlite3-dev \
|
||||
sqlite3 \
|
||||
firefox \
|
||||
firefox-esr \
|
||||
&& apt-get clean \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
# Install the required Python packages
|
||||
RUN pip install --no-cache-dir -r requirements.txt
|
||||
|
||||
# Set up Chrome WebDriver for Selenium
|
||||
RUN wget -q -O /app/chromedriver.zip https://storage.googleapis.com/chrome-for-testing-public/129.0.6668.70/linux64/chromedriver-linux64.zip && \
|
||||
unzip /app/chromedriver.zip && \
|
||||
mv /app/chromedriver-linux64/chromedriver /app && \
|
||||
chmod +x /app/chromedriver && \
|
||||
rm -rf /app/chromedriver.zip /app/chromedriver-linux64
|
||||
|
||||
# Set environment variables for Chrome and ChromeDriver
|
||||
ENV PATH=/app:$PATH
|
||||
ENV DISPLAY=:99
|
||||
|
||||
14
tgbot.py
14
tgbot.py
@ -243,7 +243,6 @@ class TelegramBot:
|
||||
|
||||
start = datetime.now()
|
||||
end = start + timedelta(days=1)
|
||||
|
||||
slots = xclient.list_slots(start, end)
|
||||
|
||||
if slots:
|
||||
@ -346,6 +345,7 @@ class TelegramBot:
|
||||
self.bot.edit_message_reply_markup(
|
||||
call.message.chat.id, call.message.message_id
|
||||
)
|
||||
|
||||
except Exception as e:
|
||||
self.bot.reply_to(call.message, f"Error: {str(e)}")
|
||||
return
|
||||
@ -513,8 +513,6 @@ class TelegramBot:
|
||||
for chat_id, slots in list(self.watchlist.items()):
|
||||
try:
|
||||
xclient = self.get_xclient(chat_id)
|
||||
except Exception as e:
|
||||
print(f"Error polling watchlist: {str(e)}")
|
||||
|
||||
available_slots = []
|
||||
for slot in slots:
|
||||
@ -552,12 +550,18 @@ class TelegramBot:
|
||||
chat_id,
|
||||
f"Slot {slot.start_stamp} is now available and has been booked for you.",
|
||||
)
|
||||
available_slots.append(slot) # Mark it to remove from watchlist
|
||||
available_slots.append(
|
||||
slot
|
||||
) # Mark it to remove from watchlist
|
||||
except Exception as e:
|
||||
self.bot.send_message(
|
||||
chat_id, f"Error booking slot {slot.start_stamp}: {str(e)}"
|
||||
chat_id,
|
||||
f"Error booking slot {slot.start_stamp}: {str(e)}",
|
||||
)
|
||||
|
||||
except Exception as e:
|
||||
print(f"Error polling watchlist: {str(e)}")
|
||||
|
||||
# Remove the expired or booked slots from the watchlist
|
||||
self.watchlist[chat_id] = [
|
||||
slot for slot in slots if slot not in available_slots
|
||||
|
||||
15
xclient.py
15
xclient.py
@ -1,4 +1,5 @@
|
||||
from selenium import webdriver
|
||||
from selenium.webdriver.firefox.options import Options
|
||||
from models import Booking
|
||||
import json
|
||||
from selenium.webdriver.common.by import By
|
||||
@ -6,9 +7,7 @@ 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
|
||||
from webdriver_manager.chrome import ChromeDriverManager
|
||||
|
||||
|
||||
class LoginFailedException(Exception):
|
||||
@ -33,13 +32,13 @@ class XClient:
|
||||
)
|
||||
|
||||
def fetch_access_token(self):
|
||||
# Set up the WebDriver (make sure to use the correct path for your WebDriver)
|
||||
driver = webdriver.Firefox()
|
||||
options = webdriver.FirefoxOptions()
|
||||
options.add_argument("--headless")
|
||||
|
||||
driver = webdriver.Firefox(options=options)
|
||||
|
||||
print("Loading x.tudelft.nl")
|
||||
driver.get("https://x.tudelft.nl")
|
||||
|
||||
print("Done loading x.tudelft.nl")
|
||||
button = WebDriverWait(driver, 30).until(
|
||||
EC.element_to_be_clickable(
|
||||
(By.XPATH, "//span[contains(text(), 'TUDelft')]")
|
||||
@ -67,18 +66,16 @@ class XClient:
|
||||
|
||||
password_input.submit()
|
||||
|
||||
time.sleep(1)
|
||||
time.sleep(2)
|
||||
|
||||
cookie = driver.execute_script(
|
||||
"return window.localStorage.getItem('delcom_auth');"
|
||||
)
|
||||
print(cookie)
|
||||
|
||||
if cookie is None:
|
||||
raise LoginFailedException("Logging in to X has failed")
|
||||
|
||||
delcom_auth = json.loads(cookie)
|
||||
print(cookie, delcom_auth)
|
||||
|
||||
driver.quit()
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user