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

from request to selenium #83

Merged
merged 1 commit into from
Oct 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 20 additions & 15 deletions src/functions/ifood_alive/main.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import base64
import requests
import sender

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager


def check_if_alive():

Expand All @@ -15,6 +19,8 @@ def check_if_alive():
}
]

# Configura o WebDriver do Chrome
driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()))

for loja in urls:

Expand All @@ -23,20 +29,19 @@ def check_if_alive():
msg = None

try:
# Faz a requisição GET para a URL
response = requests.get(url)

# Verifica se a requisição foi bem-sucedida (código 200)
if response.status_code == 200:
# Verifica se o texto "Loja Fechada" está presente no conteúdo da página
if "Loja Fechada" in response.text:
msg = f"'Loja Fechada': {loja['loja']}."
else:
msg = f"'Loja Aberta': {loja['loja']}."
else:
msg = f"Erro ao acessar a página da loja {loja['loja']}. Código de status: {response.status_code}"

except requests.exceptions.RequestException as e:
driver.get(url)
print(f"Acessando {nome_loja}: {url}")

# Tenta encontrar o elemento que indica que a loja está fechada
try:
driver.find_element(By.XPATH, "//h2[contains(text(), 'Loja fechada')]")
msg = f"'Loja Fechada': {nome_loja}."
except:
continue
finally:
driver.quit()

except Exception as e:
msg = f"Ocorreu um erro na requisição para a loja {loja['loja']}: {e}"

# Envia a mensagem para o Telegram
Expand Down
2 changes: 1 addition & 1 deletion src/functions/ifood_alive/requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
requests
selenium
Loading