Spaces:
Runtime error
Runtime error
Upload 3 files
Browse files- Dockerfile +38 -0
- app.py +133 -0
- requirements.txt +2 -0
Dockerfile
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Use a imagem base do Python
|
| 2 |
+
FROM python:3.9
|
| 3 |
+
|
| 4 |
+
# Instalar o Chrome e suas dependências
|
| 5 |
+
RUN apt-get update && apt-get install -y \
|
| 6 |
+
wget \
|
| 7 |
+
gnupg \
|
| 8 |
+
unzip \
|
| 9 |
+
&& wget -q -O - https://dl.google.com/linux/linux_signing_key.pub | apt-key add - \
|
| 10 |
+
&& sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google-chrome.list' \
|
| 11 |
+
&& apt-get update && apt-get install -y \
|
| 12 |
+
google-chrome-stable
|
| 13 |
+
|
| 14 |
+
# Instalar o ChromeDriver
|
| 15 |
+
RUN wget -O /tmp/chromedriver.zip https://chromedriver.storage.googleapis.com/114.0.5735.90/chromedriver_linux64.zip \
|
| 16 |
+
&& unzip /tmp/chromedriver.zip chromedriver -d /usr/local/bin/ \
|
| 17 |
+
&& rm /tmp/chromedriver.zip
|
| 18 |
+
|
| 19 |
+
# Criar um usuário não root
|
| 20 |
+
RUN useradd -m -u 1000 user
|
| 21 |
+
|
| 22 |
+
# Definir o diretório de trabalho
|
| 23 |
+
WORKDIR /app
|
| 24 |
+
|
| 25 |
+
# Copiar o arquivo de requisitos
|
| 26 |
+
COPY --chown=user ./requirements.txt requirements.txt
|
| 27 |
+
|
| 28 |
+
# Instalar as dependências do Python
|
| 29 |
+
RUN pip install --no-cache-dir --upgrade -r requirements.txt
|
| 30 |
+
|
| 31 |
+
# Copiar o código da aplicação
|
| 32 |
+
COPY --chown=user . /app
|
| 33 |
+
|
| 34 |
+
# Definir o usuário para executar o container
|
| 35 |
+
USER user
|
| 36 |
+
|
| 37 |
+
# Comando para iniciar a aplicação
|
| 38 |
+
CMD ["python", "app.py"]
|
app.py
ADDED
|
@@ -0,0 +1,133 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os # Import the os module
|
| 2 |
+
|
| 3 |
+
import logging
|
| 4 |
+
import time
|
| 5 |
+
from selenium import webdriver
|
| 6 |
+
from selenium.webdriver.chrome.service import Service
|
| 7 |
+
from webdriver_manager.chrome import ChromeDriverManager
|
| 8 |
+
from selenium.webdriver.common.by import By
|
| 9 |
+
from selenium.webdriver.support.ui import WebDriverWait
|
| 10 |
+
from selenium.webdriver.support import expected_conditions as EC
|
| 11 |
+
|
| 12 |
+
from datetime import datetime
|
| 13 |
+
import calendar
|
| 14 |
+
|
| 15 |
+
# Inicializar o driver do Selenium com o ChromeDriverManager
|
| 16 |
+
print("Instalando o ChromeDriver...", end="\n")
|
| 17 |
+
chromedriver_path = ChromeDriverManager().install()
|
| 18 |
+
print("ChromeDriver instalado com sucesso em " + chromedriver_path + "!",
|
| 19 |
+
end="\n")
|
| 20 |
+
|
| 21 |
+
# options = webdriver.ChromeOptions()
|
| 22 |
+
# options.add_experimental_option('w3c', False) # Desativar o protocolo W3C para usar o DevTools Protocol
|
| 23 |
+
driver = webdriver.Chrome()
|
| 24 |
+
|
| 25 |
+
# Habilitar a captura de requisições de rede
|
| 26 |
+
driver.execute_cdp_cmd('Network.enable', {})
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
# Função para encontrar um elemento usando o XPath
|
| 30 |
+
def find(xpath):
|
| 31 |
+
return WebDriverWait(driver, 10).until(
|
| 32 |
+
EC.presence_of_element_located((By.XPATH, xpath)))
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
# Função para fazer login no Marriott Vacation Club
|
| 36 |
+
def login_marriottvc():
|
| 37 |
+
driver.get('https://login.marriottvacationclub.com/login')
|
| 38 |
+
find("//input[@id='username']").send_keys(os.getenv('MARRIOTT_USERNAME'))
|
| 39 |
+
find("//input[@id='password']").send_keys(os.getenv('MARRIOTT_PASSWORD'))
|
| 40 |
+
find("//button[@type='submit']").click()
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
# Função para abrir a página de reserva de pontos
|
| 44 |
+
def open_bookvacation_marriottvc():
|
| 45 |
+
find("//a[contains(text(), 'USE POINTS')]").click()
|
| 46 |
+
find("//li[contains(text(), 'Book Using Club Points')]").click()
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
# Função para inserir o destino
|
| 50 |
+
def input_destination_marriottvc(dest):
|
| 51 |
+
destination_box = find("//input[contains(@placeholder, 'Destination')]")
|
| 52 |
+
destination_box.send_keys(dest)
|
| 53 |
+
find("//ul[@class='hotel']//li[1]").click()
|
| 54 |
+
|
| 55 |
+
|
| 56 |
+
# Função para inserir o número de hóspedes
|
| 57 |
+
def input_guests_marriottvc(num_guests):
|
| 58 |
+
find("//input[@id='numGuests']").clear()
|
| 59 |
+
find("//input[@id='numGuests']").send_keys(num_guests)
|
| 60 |
+
|
| 61 |
+
|
| 62 |
+
# Função para selecionar o mês desejado
|
| 63 |
+
def input_month_marriottvc(month):
|
| 64 |
+
find("//select[@id='searchbymonth']").click()
|
| 65 |
+
print(calendar.month_name[month].lower())
|
| 66 |
+
find(f"//option[@id='id_{calendar.month_name[month].lower()}2024']").click(
|
| 67 |
+
)
|
| 68 |
+
|
| 69 |
+
|
| 70 |
+
# Função para inserir o número de noites
|
| 71 |
+
def input_nights_marriottvc(num_nights):
|
| 72 |
+
find("//input[@id='numNights']").clear()
|
| 73 |
+
find("//input[@id='numNights']").send_keys(num_nights)
|
| 74 |
+
|
| 75 |
+
|
| 76 |
+
# Função para clicar no botão de pesquisa
|
| 77 |
+
def click_search_marriottvc():
|
| 78 |
+
find("//span[@class='search-carat']").click()
|
| 79 |
+
|
| 80 |
+
|
| 81 |
+
# Função para verificar a disponibilidade
|
| 82 |
+
def check_availability_marriottvc(check_in_day, num_nights, month):
|
| 83 |
+
input_month_marriottvc(month)
|
| 84 |
+
input_nights_marriottvc(num_nights)
|
| 85 |
+
click_search_marriottvc()
|
| 86 |
+
|
| 87 |
+
try:
|
| 88 |
+
find(
|
| 89 |
+
'//*[@id="rtWebPanel"]/div/main/div[3]/form/div/div/div[2]/div[3]/div[2]/div[1]/button'
|
| 90 |
+
).click()
|
| 91 |
+
except TimeoutException:
|
| 92 |
+
logging.error("Elemento não encontrado dentro do tempo limite")
|
| 93 |
+
|
| 94 |
+
while True:
|
| 95 |
+
try:
|
| 96 |
+
day = WebDriverWait(driver, 0.5).until(
|
| 97 |
+
EC.presence_of_element_located((
|
| 98 |
+
By.XPATH,
|
| 99 |
+
f"//button[contains(@aria-label, ' {check_in_day} ') and @class='day enabled']"
|
| 100 |
+
)))
|
| 101 |
+
print(
|
| 102 |
+
f"Dia {day.text} até {int(day.text) + int(num_nights)} está disponível no marriottvacationclub.com"
|
| 103 |
+
)
|
| 104 |
+
|
| 105 |
+
return day.text, calendar.month_name[month]
|
| 106 |
+
except:
|
| 107 |
+
check_in_day = str(int(check_in_day) + 1)
|
| 108 |
+
if int(check_in_day) > 31:
|
| 109 |
+
month += 1
|
| 110 |
+
check_in_day = '01'
|
| 111 |
+
input_month_marriottvc(month)
|
| 112 |
+
input_nights_marriottvc(num_nights)
|
| 113 |
+
click_search_marriottvc()
|
| 114 |
+
try:
|
| 115 |
+
find(
|
| 116 |
+
'//*[@id="rtWebPanel"]/div/main/div[3]/form/div/div/div[2]/div[3]/div[2]/div[1]/button'
|
| 117 |
+
).click()
|
| 118 |
+
except TimeoutException:
|
| 119 |
+
logging.error(
|
| 120 |
+
"Elemento não encontrado dentro do tempo limite")
|
| 121 |
+
|
| 122 |
+
|
| 123 |
+
# Exemplo de uso
|
| 124 |
+
login_marriottvc()
|
| 125 |
+
open_bookvacation_marriottvc()
|
| 126 |
+
input_destination_marriottvc('Marriott\'s Mountain Valley Lodge')
|
| 127 |
+
input_guests_marriottvc('2')
|
| 128 |
+
available_day, available_month = check_availability_marriottvc(
|
| 129 |
+
27, 4, 7) # Verifica a disponibilidade para 27 de Julho com 4 noites
|
| 130 |
+
|
| 131 |
+
print(f"Dia disponível: {available_day} de {available_month}")
|
| 132 |
+
|
| 133 |
+
driver.quit()
|
requirements.txt
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
selenium==4.22.0
|
| 2 |
+
webdriver-manager==4.0.1
|